Skip to content

Node version file support #209

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

Closed

Conversation

TJMcCarthy95
Copy link

Overview

Implemented the ability to define a file within a project as the holder of the projects node version such as an .nvmrc file so to mitigate duplicating node version declarations. After recently researching the ability to do this I came across this "issue" (albeit not an issue) and then came across this comment which is the implementation I had envisaged.

The implementation follows a similar flow as defined in the comment whereby the node-version input takes precedence and if not provided and the node-version-file input is, then read the provided node version file.

Commits

  • Implemented support for repository defined node version files such as '.nvmrc'

@TJMcCarthy95 TJMcCarthy95 force-pushed the add-node-version-file-support branch from d199fd6 to c3812bd Compare November 1, 2020 22:30
@runofthemillgeek
Copy link

runofthemillgeek commented Nov 13, 2020

Hey @TJMcCarthy95, thanks for this PR! I intended to take up this PR but got sidetracked with work. Few things I wanted to point out.

First one is that .nvmrc accepts formats like the following:

  • partial versions such as 12 or 12.16 (I believe this is handled right now?)
  • lts/* for the latest LTS release
  • lts/erbium for specific LTS release

and probably more. You can find this via nvm --help. I don't think this PR addresses those as well, I wrote some tests locally which failed.

There's also the problem of .nvmrc being just a feature of nvm and not being a standard. There was an attempt to standardize on a format for all of Node.js in nodejs/version-management#13 but that didn't take off as expected. There's also the .node-version file syntax, which is much simpler, and supported by multiple tools listed in https://github.com/shadowspawn/node-version-usage. So, I'd also suggest changing the input variable name to nvmrc-file to probably avoid confusion (or maybe not have that). Or, the tool could support reading such files as well (should be more straightforward than the nuances that come with .nvmrc).

I don't suppose we need to take into account every .nvmrc syntax since the purpose here is just to fetch a compatible Node.js installation. However, I'd say that it'd be useful to support the above mentioned .nvmrc formats. For eg, some of the repos I work on use lts/erbium to make sure the corresponding latest LTS release is used every time CI is run.

If you're interested, I do have a branch based off of this PR with the changes required to parse the above syntaxes. You can check it out here.

@TJMcCarthy95
Copy link
Author

Hey @TJMcCarthy95, thanks for this PR! I intended to take up this PR but got sidetracked with work. Few things I wanted to point out.

First one is that .nvmrc accepts formats like the following:

  • partial versions such as 12 or 12.16 (I believe this is handled right now?)
  • lts/* for the latest LTS release
  • lts/erbium for specific LTS release

and probably more. You can find this via nvm --help. I don't think this PR addresses those as well, I wrote some tests locally which failed.

There's also the problem of .nvmrc being just a feature of nvm and not being a standard. There was an attempt to standardize on a format for all of Node.js in nodejs/version-management#13 but that didn't take off as expected. There's also the .node-version file syntax, which is much simpler, and supported by multiple tools listed in https://github.com/shadowspawn/node-version-usage. So, I'd also suggest changing the input variable name to nvmrc-file to probably avoid confusion (or maybe not have that). Or, the tool could support reading such files as well (should be more straightforward than the nuances that come with .nvmrc).

I don't suppose we need to take into account every .nvmrc syntax since the purpose here is just to fetch a compatible Node.js installation. However, I'd say that it'd be useful to support the above mentioned .nvmrc formats. For eg, some of the repos I work on use lts/erbium to make sure the corresponding latest LTS release is used every time CI is run.

If you're interested, I do have a branch based off of this PR with the changes required to parse the above syntaxes. You can check it out here.

I appreciate you taking the time to review the PR. My intentions of implementing this weren't necessarily to support the complete feature set of .nvmrc but rather just provide the ability to have a node version defined in a file, the .nvmrc just happens to be my usage, which is the primary reason I didn't tie any variable names to nvm. I could make the README to be more explicit about that, or rather change the example to be more generic although I like what you've put together so might update accordingly.

@TJMcCarthy95 TJMcCarthy95 force-pushed the add-node-version-file-support branch from e9123de to a0d376d Compare November 19, 2020 03:06
@TJMcCarthy95
Copy link
Author

@sangeeth96 Sorry for the delay on these updates got caught up with work. I've implemented the updates using your branch as reference so when you get a chance, would be great if you could give it another review, cheers.

@bryanmacfarlane bryanmacfarlane added the enhancement New feature or request label Jan 20, 2021
@jasonkarns
Copy link

Just commenting since it's highly related: https://github.com/nodenv/actions-node-version is an action that reads .node-version file (leveraging nodenv) and exposes it as an output that can be used as an input to the setup-node action. This would be a workaround until/unless setup-node gains the ability to do it automatically.

@TJMcCarthy95 TJMcCarthy95 deleted the add-node-version-file-support branch August 8, 2021 03:17
@hkaur008
Copy link
Contributor

Is this branch deleted @alepauly ?

deining pushed a commit to deining/setup-node that referenced this pull request Nov 9, 2023
Bumps [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) from 4.25.0 to 4.26.0.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v4.26.0/packages/eslint-plugin)

---
updated-dependencies:
- dependency-name: "@typescript-eslint/eslint-plugin"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants