-
-
Notifications
You must be signed in to change notification settings - Fork 750
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
Support node.engines #618
Comments
(Thanks for the multiple links, much appreciated.) |
Proof of concept of an approach using range="$(node -e "console.log(require('./package.json').engines.node)")"
version_per_line="$(N_MAX_REMOTE_MATCHES =999 n lsr)"
versions_one_line=$(echo ${version_per_line} | tr '\n' ' ')
npx --quiet semver -r "${range}" ${versions_one_line} | tail -n 1 |
Related older issue: #192 |
Yea I can see this is non-trivial without pulling in all sorts of dependencies, or alternatively, significantly inflating the code. That being said, if it's a (relatively modern) Node project shouldn't I've never worked with JSON via Shell/Bash so I don't think I can be of much help here unfortunately. The first thing I would reach for is jq, but obviously that's even worse than the PoC above. |
I see two main cases when this won't be true. Firstly, there won't be any node when bootstrapping and using The other case is an old version of node, such as when the (A possible crude but simple work-around for implementation is to install an extra version of node if needed, to perform the check!) |
A question for interested readers, post a reaction to show your view. Is engines support that only works when there is (say) a version of node >= 6 available going to be useful in practice? 👍 Sure, I am just switching between modern versions |
nodenv has a plugin that respects the engines stanza in package.json: https://github.com/nodenv/nodenv-package-json-engine For JSON and semver support in POSIX shell, it leverages https://github.com/dominictarr/JSON.sh for parsing the package.json and https://github.com/qzb/sh-semver for the semver matching. Each of these are functional, but the plugin is certainly much slower than the standard mechanism for specifying a nodenv version (.node-version file). For most use cases, this performance overhead isn't an issue, because the version resolution occurs at the moment a user invokes |
Thanks @jasonkarns , interesting information and links |
Heroku have a semver api for node which is an interesting alternative, but the backing project has been archived: https://semver.io |
Can avoid invoking full semver for the simpler expressions that map onto supported
|
I have a first cut at implementation and reasonably happy, noisy progress so can tell what is going on ("resolving" is using npx and semver and a slow step):
|
Oh, I like that idea. Would be a nice improvement to the node version plugin as well; to short circuit and avoid the semver evaluation when possible. |
I have released support in Give it a try if you are keen! Comments welcome here in this thread, or open an issue there. e.g. |
Released in v6.7.0 |
The current implementation with |
Many projects use the
engines.node
property in thepackage.json
file to denote the version of Node.js to be used for that specific project. Although it isn't a required specification, it is ubiquitous enough that there are serious discussions around supporting it in competing tools (see below).Also, some additional context from #547.
Prior discussions
In an issue on the
nodejs/version-management
repo,engines.node
is one of the proposed alternatives: Agree on a standard format for a.node-version
file? nodejs/version-management#13This feature is a frequently upvoted feature request on the NVM repository: Use package.json engines version? nvm-sh/nvm#651.
Precedent
ps-nvm
already supports this: https://github.com/aaronpowell/ps-nvm#packagejson-enginesnodePotential issues
From: #547 (comment)
The text was updated successfully, but these errors were encountered: