-
-
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
Added in comments in .nvmrc #2288
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's please separate out the changes that are related to "nvmrc comments", and the rest.
@@ -446,6 +454,28 @@ Found '/path/to/project/.nvmrc' with version <5.9> | |||
Now using node v5.9.1 (npm v3.7.3) | |||
``` | |||
|
|||
`.nvmrc` files may have comments. The following is the notation to have a comment inside a `.nvmrc` file: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a pretty major feature that I'm pretty convinced I do not want. In the future it might be best to discuss this sort of thing via issue first, so you don't end up doing wasted work.
I think before deciding what code changes are needed, to this PR or nvm itself, we should have nonzero discussion about what the goal is, and why this feature is needed. |
This comment has been minimized.
This comment has been minimized.
nvm.sh
Outdated
NVM_RC_VERSION="$(command head -n 1 "${NVMRC_PATH}" | command tr -d '\r')" || command printf '' | ||
NVM_RC_VERSION="$(command cat "${NVMRC_PATH}" | command tr -d '\r' | sed -e 's/\s*#.*$//' | sed -e '/^\s*$/d' | command tr -d '\n' | command tr -d '\t' | command head -n 1 | sed -e 's/[[:space:]]//g')" || command printf '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recently, I had a .nvmrc
file inside one of my projects. As you know, most projects have only one, and I wanted to add in some comments. These line changes above, are the main part of this pull request. Instead of running head
on the file, I replaced it for cat
. Next, the next two sed
commands remove comments. I also removed newlines and tabs inside. After that, I ran head -n 1
on everything to get only the first line. In the case of the following scenario:
node # This is the nvm version
There is going to be a space thereafter where it says node
. Next, I also removed spaces for that scenario. That is a quick read of what is happening in the main part of the pull request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, but why did you want to add comments? The file is named "nvm rc", who needs the extra hint that it's for nvm?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand your point. The comment does not have to be:
node # This is for nvm
It can also be:
v14.0.23 # This is the node version to be installed
As you can see, the comment gives some description to someone who didn’t come across .nvmrc
. I wanted to add comments to give a quick explanation of the .nvmrc
. The answer is the same as asking, why do you ever write comments. To make sure that anyone else understands your code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right - but comments in code should never explain "what", only "why" or history/motivation, and in this case, git log .nvmrc
should tell you precisely that in the commit messages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't hurt to add in support for comments. It gives people the choice to describe why the .nvmrc
is there and what is in it. I still couldn't understand why you don't want comments in .nvmrc
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Say we are making a change that also allows the npm
version. Then, if the .nvmrc
allows comments, it will look like this:
# This is a comment
node # This is the nodejs version
v6.14.7 # This is the npm version
In that scenario, if we remove the head -n 1
at the end, the output will be:
node
v6.14.7
In the code, we can simply pick whether we want the first version or the second version (The node
version or the npm
version). I don't see how it complicates everything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ljharb those are good puritan points, and perhaps you're right, but I think in our case on a large project, where people don't even necessarily know what nvm is let alone an nvmrc
it can be helpful to explain e.g. "# we're fixing to 16.2.0 because of this bug " and or simply re-document the default behaviours "this version will be used by default when you run nvm install. It's an agreed upon, tested & supported node version for the project." Coordinating communications on projects with people with a wide range of backgrounds/seniority can mean that documenting "what" is helpful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn’t that what git is for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, but I don't think expecting my interns to read a git lens comment is as easy as having them read the file contents.
Should we just put all our efforts into teaching interns the correct methodologies and stop perpetuating incompetence in our industry? Probably, yes.
On the other hand, if the world is covered in unnecessary thorns, is it easier to wear shoes than of rid the world of thorns? Sometimes the pragmatic option is the correct option.
Anyway - you make good points, and I can appreciate why you'd say no. JSON doesn't have comments either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ljharb I can maybe put good example - in comment there could be link to issue that require to keep node in specific version due to some complications something like - for now we have this comment on CI workflows with node version - i would like to move it into nvmrc
without loosing information why it is locked to particular version.
v16.10.0 # https://github.com/facebook/jest/issues/11956
But as keeping nvm
simple is also good valid point.
@ljharb Do we want to take action on this one with the intention of getting it merged ? |
@sladyn98 I'm still not convinced it's worth the complexity. |
1d6999d
to
d7ba60d
Compare
@ljharb if you plan to not merge in the future don't you think we should close it |
I'm undecided, which is why it's left open. I don't believe in closing a PR unless it's certain to never land. |
Would be very useful for "make sure you update the <docker container/CI config/package.json engines> too!" style comments |
Do you mean allowing a .nvmrc, like this?:
The reason that this shouldn’t be added is because it removes support for aliases with double quotes and anyways, the following works:
|
No, I mean the feature (as you propose it) would be useful for adding comments to the .nvmrc to remind people to change values elsewhere. e.g.
This was partially in response to
further up. |
@penx isn't a CI job that fails when those aren't in sync much more effective than a comment? |
@ljharb yes it would, but it may not always be feasible or convenient e.g.
|
Another useful example of a useful comment (and one that isn't particularly suited for git commit messages, IMO):
|
@jasonkarns i mean, the symlink part is already self-evident from "the actual symlinks in the filesystem"; it's just the issue URL that has no place to go. but fair, that's a good use case. |
@ljharb if we assume that it being a symlink is even evident at all. Some ides/editors don't distinguish that a file is a symlink; and even those that do, don't necessarily make it -obvious-. Add insult to injury, these are hidden files so many project views wouldn't show them in a listing. All that to say: I -had- this exact comment in a symlink in a project recently and had to remove it for compatibility. :) |
First, about why you want comments in the
If you are explaining what an Several people have pointed this out above, so I'd like to reiterate the main reason I have comments in configuration files is to document bugs that force me to use a specific configuration option, .e.g. "Bug X causes Y so we set our config to Z as a work-around. [link to issue]" That kind of information needs to be right next to the configuration or someone (maybe even me!) will "fix it" later not realizing it causes a bug, e.g. "Huh, this file is out-of-date. The value of v14.13.1 should be updated to the latest v14.19.1. Oops. I broke something." IMO, I think all configuration files should be able to have comments in them. Don't get me started on Lastly, I was looking at the code this PR changes and noticed this line in the original NVM_RC_VERSION="$(command head -n 1 "${NVMRC_PATH}" | command tr -d '\r')" || command printf '' Only the first line in
And I got an error: And when I changed the file to:
The So, all we really need to do is make this officially supported in docs; no code changes, afaics. |
@JohnAlbin however, if you do that, it's guaranteed to break in the future, because eventually nvm will support parsing additional content from successive lines. |
@ljharb said:
Agreed. From my previous comment:
Which is why I said we need to decide how to document how comments should work. Right now, afaics, the entire
To add the official ability to comment the file we need to decide what format comments are allowed to use. And whether we want to reserve the second or third lines for forward compatibility with future features. FYI, I prefer the |
This is our exact use case We pin a project to a specific node version and I would like to leave a comment in nvmrc to say why we are using that version (e.g. "don't upgrade to v16 yet because X breaks") Yes we could put that comment somewhere else in documentation, but this seems like the best place to leave a reminder (so that the person bumping the version will see it) |
I created a new issue so we can discuss adding comments to #3336 Allow comments in .nvmrc config file |
Overview
I added in support for comments in the
.nvmrc
file.List of Updates
nvm_rc_version
to strip commentsnvm
aliases