-
-
Notifications
You must be signed in to change notification settings - Fork 8k
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
Use package.json engines version? #651
Comments
Hmm - I could definitely add this as an alternative, when |
NPM treats So it would be of great help if |
@assaf it already can! Just put a |
How do you tell |
That's not what I meant - I meant you just manually put a version in that file and commit that to the repo. |
That's not what I was asking for. Having multiple files that specify which version of iojs/Node is in use, just means more things breaking because "works on my machine". Common sense is to keep the project DRY and have a single authoritative specification of the version in use. |
Right, I agree with that. The problem is that Thus, since they're for two separate purposes, I wouldn't want to get more DRY than two separate configurations. "Too DRY" can be worse than "not DRY enough". |
If you don't like this feature don't use it. I'd like to have such a feature that I will then choose to use for my projects. |
"if you don't like it then don't use it" is not really a good justification for adding any feature to any project. It's nice that you want it, and thanks for offering your thoughts, but:
In other words, even if I thought this was a good feature on its face, there's just no way it's practical, so it simply can't happen. I'm happy to review a PR in the future if someone can come up with a simple way to achieve it, but I remain opposed on the semantic appropriateness of this feature and would need to be convinced. |
I'm most familiar with https://github.com/stedolan/jq which Heroku uses to parse PR would be pointless, we can't even agree that my use case for |
Yes but that would be an additional dependency to install, which currently If you wrote a small commandline script that did what you wanted and supplied the version to |
Thanks, that's great - I'm not stoked on the reliance on a heroku app for semver resolution, and the usual advice in #iojs on freenode is to put the iojs version in
Currently, we have |
If you set The semver version is used for resolving ranges. Heroku maintains it as part of their build infrastructure, a front-end to nodejs.org/iojs.org, so it's already used by many of the people who will find this feature useful, to develop and deploy against the same version. However, if you need repeatable builds, you should set the specific version in This works. It allows you to use It does not deprecate or change existing functionality. It should still be possible use |
Awesome, that behavior makes sense to me, thanks for clarifying. Currently, if I don't have a |
I don't think it's a good idea to break current behavior. Could be a new command, or use an alias, maybe |
Interesting idea! As an alias, it'd have to be overridable, just like |
Alternatively, it could be a path, so And if you're in a directory that contains a
|
+1 to @assaf's request here. I was in the middle of coding stuff into my shell files to do exactly this when I discovered this issue. I'd also like to note that from my perspective there are big, important differences between an application and a reusable module, and many things in the npm ecosystem fail to recognize this, causing me much frustration. This is an application-driven feature request where your code is the first thing the node binary loads, and I think |
I ran across this issue when I had the same thought that it would be convenient that I would like share that you can still use the info from package.json with nvm by utilizing jq as follows: $ nvm use $(jq -r .engines.node package.json) And if you don't have the version installed yet, you can use the same concept with $ nvm install $(jq -r .engines.node package.json) Yeah, thats a lot of typing, but you could alias it if you really wanted to. |
A version of grabbing |
Although that won't work unless you already have |
Is anyone actively working on a command line |
FYI, nodenv has a passable plugin api copied from rbenv. It was pretty straightforward to build a plugin to parse package.json engines after @assaf did all the hard work :) We're looking at using sh-semver to evaluate semver ranges without a network call or a node dependency. |
Just wanted to chime in to say that I agree with @assaf's original sentiment that locking to specific node version should be encouraged -- lack of version constraint is a good thing imho, should folks choose to use engines.node |
👍 To the original suggestion. It's super helpful in having a smooth process for getting people up and running on a project locally, especially from zero. I'm imagining a workflow that would be as simple as:
Even better, if there were a way to |
Thanks for reassuring me of the path to sanity for this. Thanks for linking the PR!!
Or ideally, if it could just use package.json "engines", that would stop the need for having the version in .nvmrc and we wouldn't have to add it to all our repos. |
This will be a nice addition to nvm since every project has a Every tool likes to add more unnecessary dot files :( |
I wish the nvmrc were not necessary, but it still is. See nvm-sh/nvm#651 I think nvmrc is the most popular Node version manager, so it _probably_ makes sense to add the `.nvmrc`. If we want to skip this and go just with the `package.json`, that's fine too.
I wish the nvmrc were not necessary, but it still is. See nvm-sh/nvm#651 I think nvmrc is the most popular Node version manager, so it _probably_ makes sense to add the `.nvmrc`. If we want to skip this and go just with the `package.json`, that's fine too.
I am glad to see that there is still interest to look into this, I hope we get a solution soon! |
+1 to this feature request! My 2c: my current company has an Since this warning is important, and for other reasons, we can't remove the We could solve that problem with automation — a step that makes sure
For now, I'm sticking with jamsyoung's suggestion, |
@lautarodragan indeed, "automation" is how that's been solved at all of my past employers. (re jq, you can use |
(My query may sound a bit off topic and naive) Thanks |
@ljharb is there was a way use to |
nvm can't assume that node is already available, so it can't run npx. |
Here's my solution, supports |
I'm following this simple approach alias nv="cat package.json | grep '\"node\": ' | grep -o '[0-9.]*'"
nvm use $(nv) |
Careful with that; JSON doesnt require a space after the colon, and npm dist-tags i believe can also be used there. |
For anyone interested, i created package called https://www.npmjs.com/package/nvm-auto Simple usage:
Works for |
I wish the nvmrc were not necessary, but it still is. See nvm-sh/nvm#651 I think nvmrc is the most popular Node version manager, so it _probably_ makes sense to add the `.nvmrc`. If we want to skip this and go just with the `package.json`, that's fine too.
@maintainers tl;dr. If I submit a patch that adds this feature, would you land it? |
# Motivation By default, `nvm` installs the latest `node`. But the latest nodejs does not work with this repo; `npm ci` fails. I note that `nvm` explicitly does NOT use the engines version in `package.json`. This has been discussed to death in nvm-sh/nvm#651 # Changes * Add an `.nvmrc` configuration file that specifies node version 20. # Tests I have manually run `nvm install` locally and that has worked. I'm not sure whether we want to use `nvm` in CI, so I have changed nothing there.
I wish the nvmrc were not necessary, but it still is. See nvm-sh/nvm#651 I think nvmrc is the most popular Node version manager, so it _probably_ makes sense to add the `.nvmrc`. If we want to skip this and go just with the `package.json`, that's fine too.
I wish the nvmrc were not necessary, but it still is. See nvm-sh/nvm#651 I think nvmrc is the most popular Node version manager, so it _probably_ makes sense to add the `.nvmrc`. If we want to skip this and go just with the `package.json`, that's fine too.
Run
nvm use
will read local package.json's engines.node and change version accordingly.Or anyway that auto switch the version.
The text was updated successfully, but these errors were encountered: