When developing JS libraries meant for node what is the best practice for writing a library that leverages es6 features but still works with versions of node that don't support es6?
For instance, I have an open source library that I wrote a couple years ago in es5 but I want to upgrade it to use es6. Do I have to say to my users that if you want to use my library going forward you're version of node has to be upgraded as well? What is the community preferred practice for dealing with this?
For instance, I have an open source library that I wrote a couple years ago in es5 but I want to upgrade it to use es6.
First you have to decide if you're going to continue to support an ES5 version of your library or not. If you are, then you would probably end up with two branches of your library, one that works with ES5 and one that requires ES6 and takes advantage of the capabilities in ES6. You'd have to decide how much effort you put into the ES5 version and for how long. Presumably, you'd fix significant bugs found in that version for at least some period of time and eventually you'd sunset that version for no new changes/fixes.
If this library is destined for node.js as the target environment, then you could just have your ES6 library immediately test to see if the appropriate environment is available at startup and, if not, then log to the console and throw an exception with a meaningful message as the error to advise the developer if they have the wrong environment for this library.
If you are not going to continue to support the ES5 version of the library with additional features or fixes, then you'd probably branch your repository at the last version that is for ES5 so the open source community could continue to support/enhance it if separately if they so chose.
Do I have to say to my users that if you want to use my library going forward you're version of node has to be upgraded as well?
You don't HAVE to do anything. It's up to you to do what you think is appropriate for your library and your situation. Since it's open source, you may also want to consider what your open source contributors want to do.
What is the community preferred practice for dealing with this?
There is no specific community preference that applies equally well to all libraries or situations. One starting point for node.js support is to look at what node.js does for its own versions and look at how long it offers continuing support for older versions. You don't have to be that generous (it depends upon your situation), but you probably don't need to be more generous than node.js itself is with older version support since at that point a developer would be running an old version of node.js that was no longer support itself. This is a look at node.js version support: https://github.com/nodejs/LTS.
You will notice in that chart that support for everything before v4 ends in Dec. 2016. And there were significant ES6 features (not all though) in v4, so if you could build off the ES6 features in v4, then it would probably be reasonable to require node.js v4 fairly soon. If you're looking to use ES6 features that are only in node.js v6, then you'd really have to poll your user base to find out how much of a hardship it would be if your branch with new feature development require node.js v6. node.js v6 is just going LTS (long term support) now so it's really at the beginning of its longer support cycle now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With