Skip to content
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

feat(cli): Enforce a node version via toml option #8907

Closed
wants to merge 1 commit into from

Conversation

Josh-Walker-GM
Copy link
Collaborator

ping @thedavidprice, @jtoar - I didn't really have much information about what this feature was intended to be. I had agreed to take it on to free up Dom a little more.

Adds a toml option like so:

[node]
  version = "18 || 20"

It defaults to undefined which then avoids any checks. When set the CLI will perform a check before all commands and fail if the current node version does not match the specification set in the toml.

Examples:
Screenshot from 2023-07-14 13-28-27

@Josh-Walker-GM Josh-Walker-GM added the release:feature This PR introduces a new feature label Jul 14, 2023
@Josh-Walker-GM Josh-Walker-GM added this to the v6.0.0 milestone Jul 14, 2023
@jtoar
Copy link
Contributor

jtoar commented Jul 14, 2023

@Josh-Walker-GM I think you just about nailed it in terms of implementation. Besides improving the copy in the error message a bit, the main question is really just where does this go in redwood.toml? We may need to a little clearer that this only for development. (I don't want to think about it right now. 😅)

@Josh-Walker-GM
Copy link
Collaborator Author

Note: Should this also check for node versions less than we support so that users can't accidentally run in v16 or whatever?

@jtoar jtoar modified the milestones: v6.0.0, next-release Jul 27, 2023

import { getConfig } from '@redwoodjs/project-config'

export async function enforceNodeVersionConfig() {
Copy link
Collaborator

@dac09 dac09 Jul 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Josh-Walker-GM sorry to insert myself into this conversation, I'm a little bit scared of doing checks on the CLI on every run - could I suggest that we wrap the whole thing in a try catch?

This way if anything fails in the logic, for example cooercing the semver version (which happens sometimes, for example with the experimental releases) - it won't stop someone from using rw.

Up to you anyway, just a suggestion.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's certainly something we should to do, happy to.

@jtoar jtoar modified the milestones: next-release, v6.1.0 Aug 12, 2023
@jtoar jtoar modified the milestones: next-release, v6.2.0 Sep 2, 2023
@jtoar jtoar modified the milestones: next-release, v6.3.0 Sep 16, 2023
@Tobbe
Copy link
Member

Tobbe commented Dec 18, 2023

I don't have the full back-story here, but I'm going to make us hold off on this.

I think it's in the best interest of a RW app developer to have the same version of Node in all environments the app runs. Most notably both locally, with all devs on the team, and also when deployed. So I don't think we should allow specifying a range or options of different allowed node versions (like 18 || 20).

When we build the @redwoodjs/<package> packages we build with a specific Node version (Node 18 for RW v6). That means we might use APIs that are only available in Node 18. So we can't guarantee our packages work on Node 16 or 20 for example. For RW v7 we'll switch to Node 20. So we will no longer be able to guarantee that our packages work on Node 18. So if we wanted to officially support both Node 18 and 20 we'd have to publish different versions of all our @redwoodjs packages built for those different node versions. Or we make sure we only ever use features that are available across all node versions we want to support, and include all those Node versions in CI, which I'm also not a big fan of. CI is slow enough as it is.

Finally, seeing how quick we've been to adopt new node versions lately, and Netlify's new process on supporting new Node versions I think this might not be as important for our users as it once was.

@Tobbe Tobbe closed this Dec 18, 2023
@thedavidprice
Copy link
Contributor

@Tobbe I was adding this to our list to talk about tomorrow. It's about two things:

  • teams working on same version
  • deploy providers not supporting versions

TBD

@jtoar jtoar removed this from the next-release milestone Dec 21, 2023
jtoar added a commit that referenced this pull request Dec 22, 2023
…es (#9728)

Continuation of #8907.
Following up on our meeting today (@Tobbe, @thedavidprice; this PR
doesn't implement the configurable engines functionality yet).

This PR

- removes the `.nvmrc` file from CRWA and test project fixtures
  
Setup deploy commands should add node version files if they need them,
preferably something nvm agnostic like Netlify's `.node-version`

- removes yarn from engines in CRWA's root package.json since it doesn't
do anything and just creates confusion

- adds a node version check to build and dev 

This piece of middleware is lightweight; it doesn't involve a child
process or the file system, it just checks against `process.version`. I
also removed the babel check because it's been ages since we've made
that change and original concerns against checking for the node version
were about adding overhead tot he CLI. So let's remove unnecessary
middleware if we're going to add more

Right now, the node version check just emits a warning. Should it error
out? (I should've taken better notes.)

Build:


![image](https://github.com/redwoodjs/redwood/assets/32992335/e0d2ced6-7b52-448e-96a1-08a45aac64e0)

Dev:


![image](https://github.com/redwoodjs/redwood/assets/32992335/d78069eb-bd6c-4ac9-b936-b90f704b5c5c)

## Tasks

- [ ] research deploy providers and update `yarn rw setup deploy`
commands
- [x] settle on warning or error for build and dev
- [x] settle on the contents of the message
- [x] update CRWA

### Deploy providers

- [x] baremetal

  Pretty sure it's completely up to you.

- [x] coherence

Via Nixpacks, `engines.node` in the root package.json:
https://nixpacks.com/docs/providers/node#setup.

- [x] flightcontrol

Via Nixpacks, `engines.node` in the root package.json:
https://www.flightcontrol.dev/docs/getting-started/javascript/setting-node-version#using-the-packagejson-file.

- [x] netlify

Via the `.node-version` file, or via in `netlify.toml`; see
https://docs.netlify.com/configure-builds/manage-dependencies/#node-js-and-javascript,
https://docs.netlify.com/configure-builds/file-based-configuration/#sample-netlify-toml-file.

- [ ] vercel

Takes its cue from engines.node in the root package.json:
https://vercel.com/docs/functions/serverless-functions/runtimes/node-js#version-overrides-in-package.json.

- [x] render

Same as netlify more or less, but also respects `engines.node` in the
root package.json: https://docs.render.com/docs/node-version.
Tobbe pushed a commit that referenced this pull request Dec 22, 2023
…es (#9728)

Continuation of #8907.
Following up on our meeting today (@Tobbe, @thedavidprice; this PR
doesn't implement the configurable engines functionality yet).

This PR

- removes the `.nvmrc` file from CRWA and test project fixtures

Setup deploy commands should add node version files if they need them,
preferably something nvm agnostic like Netlify's `.node-version`

- removes yarn from engines in CRWA's root package.json since it doesn't
do anything and just creates confusion

- adds a node version check to build and dev

This piece of middleware is lightweight; it doesn't involve a child
process or the file system, it just checks against `process.version`. I
also removed the babel check because it's been ages since we've made
that change and original concerns against checking for the node version
were about adding overhead tot he CLI. So let's remove unnecessary
middleware if we're going to add more

Right now, the node version check just emits a warning. Should it error
out? (I should've taken better notes.)

Build:

![image](https://github.com/redwoodjs/redwood/assets/32992335/e0d2ced6-7b52-448e-96a1-08a45aac64e0)

Dev:

![image](https://github.com/redwoodjs/redwood/assets/32992335/d78069eb-bd6c-4ac9-b936-b90f704b5c5c)

- [ ] research deploy providers and update `yarn rw setup deploy`
commands
- [x] settle on warning or error for build and dev
- [x] settle on the contents of the message
- [x] update CRWA

- [x] baremetal

  Pretty sure it's completely up to you.

- [x] coherence

Via Nixpacks, `engines.node` in the root package.json:
https://nixpacks.com/docs/providers/node#setup.

- [x] flightcontrol

Via Nixpacks, `engines.node` in the root package.json:
https://www.flightcontrol.dev/docs/getting-started/javascript/setting-node-version#using-the-packagejson-file.

- [x] netlify

Via the `.node-version` file, or via in `netlify.toml`; see
https://docs.netlify.com/configure-builds/manage-dependencies/#node-js-and-javascript,
https://docs.netlify.com/configure-builds/file-based-configuration/#sample-netlify-toml-file.

- [ ] vercel

Takes its cue from engines.node in the root package.json:
https://vercel.com/docs/functions/serverless-functions/runtimes/node-js#version-overrides-in-package.json.

- [x] render

Same as netlify more or less, but also respects `engines.node` in the
root package.json: https://docs.render.com/docs/node-version.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:feature This PR introduces a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants