upgradejs / depngn

A CLI tool to find out if your dependencies support a given version of node.
MIT License
102 stars 5 forks source link

[bugfix]: support Node versions 10-14 #35

Closed kindoflew closed 1 year ago

kindoflew commented 1 year ago

This PR fixes a bug where depngn would crash on Node versions <14. (Resolves #34)

Context

The fs/promises module was added to Node in v14. Before that, starting in v10, the Promises API was available under fs.promises (so, you'd import it like require('fs').promises). https://nodejs.org/api/fs.html#promises-api

One solution to this would have been to conditionally import the correct module using dynamic imports:

const { access } = compare(process.version, '14.0.0', '<')
    ? (await import('fs')).promises
    : await import('fs/promises');

But I didn't like the idea of littering the code with conditionals and (potentially) unnecessary async stuff. So, I opted for importing the old sync versions and wrapping them in promisify (which has the added benefit of being available starting in Node v8, so potentially more "unofficial" support?).

Changes

QA

Unfortunately, I'm now on an M1 Mac which hates letting nvm install Node versions <14 for some reason, so I can't manually test this on my machine (although, I did QA with newer Node versions and ran tests and everything works).

To QA you would:

Also

Hey everybody! Hope you're all doing well!

JuanVqz commented 1 year ago

@kindoflew hey! everything is good so far, I hope the same is for you.

I know it's not easy to leave your package manager (I didn't want to stop using rvm for ruby stuff).

Have you heard about asdf manager?

It has an adapter for javascript, ruby and more...

I've heard they use a "pre-build" ruby to have support with M1 chips, wondering if that applies to the JS manager if you are interested in having an old version probably you can try it.

KostiantynPopovych commented 1 year ago

Looks good, @kindoflew, thank you!)

chawes13 commented 1 year ago

Can you please publish this when you have the chance?