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

Node version checking #2142

Merged
merged 1 commit into from
May 11, 2023
Merged

Node version checking #2142

merged 1 commit into from
May 11, 2023

Conversation

nataliecarey
Copy link
Contributor

Adding a check for node version before running the kit. Content needs reviewing (@joelanman).

@joelanman
Copy link
Contributor

current output:

npm run dev

> @ dev /private/var/folders/27/v2ycqnfd3t507l9c4qwvrx1w0000gp/T/test-prototype
> govuk-prototype-kit dev


You're using Node v12.22.6 but GOV.UK Prototype Kit v13 only supports node versions 16 and 18.

Please upgrade to node 18 and try again.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ dev: `govuk-prototype-kit dev`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the @ dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/joelanman/.npm/_logs/2023-04-25T14_26_42_319Z-debug.log

@joelanman
Copy link
Contributor

We'll do a warning for now, we can see if that works for users. An error may be a breaking change so we can consider that in v14

@joelanman
Copy link
Contributor

output when using Node 12:

npm run dev 

> @ dev /private/var/folders/27/v2ycqnfd3t507l9c4qwvrx1w0000gp/T/test-prototype
> govuk-prototype-kit dev



You're using Node v12.22.6 but GOV.UK Prototype Kit v13 only supports node versions 16 and 18.

Please upgrade to node 18 and try again.


/Users/joelanman/projects/govuk-prototype-kit/migrator/upgrade-steps.js:17
      return line === originalContentLine?.trim()
                                          ^

SyntaxError: Unexpected token '.'
    at wrapSafe (internal/modules/cjs/loader.js:915:16)
    at Module._compile (internal/modules/cjs/loader.js:963:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/Users/joelanman/projects/govuk-prototype-kit/migrator/migration-steps.js:28:31)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ dev: `govuk-prototype-kit dev`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the @ dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/joelanman/.npm/_logs/2023-04-25T15_54_27_043Z-debug.log

@joelanman
Copy link
Contributor

output when using Node 14

You're using Node v14.18.1 but GOV.UK Prototype Kit v13 only supports node versions 16 and 18.

Please upgrade to node 18 and try again.


GOV.UK Prototype Kit 13.6.1

starting...

Watching dependency govuk-prototype-kit as it's a symbolic link.

You can manage your prototype at:
http://localhost:3000/manage-prototype

The Prototype Kit is now running at:
http://localhost:3000

@joelanman
Copy link
Contributor

joelanman commented Apr 25, 2023

We've found that the kit runs in v14 but not older (due to optional chaining). So we suggest 2 outcomes:

If the major Node version is v14, have a warning:

You're using Node v14.18.1 

The GOV.UK Prototype Kit only supports Node v16 and v18. Some features may not work with your version.

You can upgrade to Node v18 at https://nodejs.org/en/download

If it is older, have an error (Exit 0 to avoid the nasty stack trace)

You're using Node v12.22.6 

The GOV.UK Prototype Kit only supports Node v16 and v18. 

You can upgrade to Node v18 at https://nodejs.org/en/download

@joelanman
Copy link
Contributor

seems to work well for npm run dev - does it affect npx govuk-prototype-kit create? I wasn't sure how to test that

@BenSurgisonGDS
Copy link
Contributor

BenSurgisonGDS commented May 5, 2023

seems to work well for npm run dev - does it affect npx govuk-prototype-kit create? I wasn't sure how to test that

Use npm pack within the folder of the govuk-prototype-kit project to create govuk-prototype-kit@13.6.2

Then make sure you are testing the version of node you want (I'm using nvm) nvm use 12

Then run the create command using the packed version of the kit and specifying the version as the packed version
npx govuk-prototype-kit@govuk-prototype-kit-13.6.2.tgz create --version=govuk-prototype-kit-13.6.2.tgz node-test-version-12

@joelanman
Copy link
Contributor

joelanman commented May 5, 2023

just to record our findings so far, on create:

node 12 stops with an error (as expected)
node 14 gives a warning then crashes during the install step (not as expected)

@joelanman
Copy link
Contributor

the error came from a wrong command, not any of this work, this looks good

BenSurgisonGDS
BenSurgisonGDS previously approved these changes May 9, 2023
Copy link
Contributor

@BenSurgisonGDS BenSurgisonGDS left a comment

Choose a reason for hiding this comment

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

Approved as Joe thinks it looks ok.

bin/cli Outdated
const isStage2Migrate = argv.command === 'migrate' && process.argv[3] === '--'
const isStage2Create = argv.command === 'init'

// Do not display error or warning messages when this is stage2 of create or migrate
Copy link
Contributor Author

Choose a reason for hiding this comment

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

What's the reason for making exceptions for "stage 2"? I'm nervous about this because it puts the argument parser into a scope where it needs to run on node versions which we don't support. Anything above the process.exit line needs to be much more widely compatible than the rest of our codebase.

Copy link
Contributor

Choose a reason for hiding this comment

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

This was to prevent the warning message being displayed twice. If you have a better way to prevent this, it would be great.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd like to use a flag to suppress the message - we can check for that with simpler code which will be more backwards compatible and less likely to break in the future as there is no require before the version check. For example this line works in the latest version of node v4: !!process.argv.find(x => x === '--suppress-node-version-warning' ).

The argv parser is likely to get more complex and I don't think it's good to have to stick to older syntax in that file.

@joelanman
Copy link
Contributor

joelanman commented May 9, 2023

just to say this will need a changelog - I'd say it's a fix as it's not a new feature

@nataliecarey nataliecarey force-pushed the node-version-checking branch 2 times, most recently from ed98d85 to 6ad98eb Compare May 9, 2023 15:53
@nataliecarey
Copy link
Contributor Author

I have made some updates and the output is below for various versions. I've picked the latest of each version. I've gone right back just to show how the errors differ and to see whether we want to improve the messaging for these earlier versions.

I have proved locally that I can show the error message on every version back to Node 0.8 (the earliest I can install on my machine) but that requires a code change I'd rather not make and I assume that there's no need to improve the messaging for such old versions.

Node 19

You're using Node v19.9.0
The GOV.UK Prototype Kit only supports Node v16 and v18.

You can download Node v18 at https://nodejs.org/en/download

GOV.UK Prototype Kit 13.6.1

starting...

Node 18

GOV.UK Prototype Kit 13.6.1

starting...

Node 16

GOV.UK Prototype Kit 13.6.1

starting...

Node 14

You're using Node v14.21.3
The GOV.UK Prototype Kit only supports Node v16 and v18.

You can upgrade to Node v18 at https://nodejs.org/en/download

GOV.UK Prototype Kit 13.6.1

starting...

Node 12

You're using Node v12.22.12
The GOV.UK Prototype Kit only supports Node v16 and v18.

You can upgrade to Node v18 at https://nodejs.org/en/download

Node 10

You're using Node v10.24.1
The GOV.UK Prototype Kit only supports Node v16 and v18.

You can upgrade to Node v18 at https://nodejs.org/en/download

Node 8

You're using Node v8.17.0
The GOV.UK Prototype Kit only supports Node v16 and v18.

You can upgrade to Node v18 at https://nodejs.org/en/download

Node 6

/Users/[...]/govuk-prototype-kit/bin/cli:91
async function updatePackageJson (packageJsonPath) {
      ^^^^^^^^

SyntaxError: Unexpected token function
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:549:28)
    at Object.Module._extensions..js (module.js:586:10)
    at Module.load (module.js:494:32)
    at tryModuleLoad (module.js:453:12)
    at Function.Module._load (module.js:445:3)
    at Module.runMain (module.js:611:10)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:160:9)

Node 4

/Users/[...]/govuk-prototype-kit/bin/cli:23
const { spawn, exec } = require('../lib/exec')
      ^

SyntaxError: Unexpected token {
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:140:18)
    at node.js:1043:3

Node 2

/Users/[...]/govuk-prototype-kit/bin/cli:23
const { spawn, exec } = require('../lib/exec')
      ^
SyntaxError: Unexpected token {
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:413:25)
    at Object.Module._extensions..js (module.js:448:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:471:10)
    at startup (node.js:117:18)
    at node.js:953:3

Node 0

/Users/[...]/govuk-prototype-kit/bin/cli:23
const { spawn, exec } = require('../lib/exec')
      ^
SyntaxError: Unexpected token {
    at exports.runInThisContext (vm.js:73:16)
    at Module._compile (module.js:443:25)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)
    at node.js:814:3

@joelanman
Copy link
Contributor

joelanman commented May 9, 2023

nice, though I think we lost some content - the warning line should be:

The GOV.UK Prototype Kit only supports Node v16 and v18. Some features may not work with your version.

Personally I don't think we should care about Node 6 and before issues - thats very old

Needs a changelog entry

@BenSurgisonGDS BenSurgisonGDS self-requested a review May 9, 2023 19:31
@BenSurgisonGDS BenSurgisonGDS dismissed their stale review May 9, 2023 21:54

Major changes since I approved it and unit tests are failing

Copy link
Contributor

@joelanman joelanman left a comment

Choose a reason for hiding this comment

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

I think you've changed the message for warning and error - they are slightly different messages

"Some features may not work with your version." only applies to the warning

@nataliecarey
Copy link
Contributor Author

Thanks @joelanman

I've implemented that now. The output is as follows:

Node 19

You're using Node v19.9.0
The GOV.UK Prototype Kit only supports Node v16 and v18. Some features may not work with your version.

You can download Node v18 at https://nodejs.org/en/download

GOV.UK Prototype Kit 13.6.2

starting...

Node 14

You're using Node v14.21.3
The GOV.UK Prototype Kit only supports Node v16 and v18. Some features may not work with your version.

You can upgrade to Node v18 at https://nodejs.org/en/download

starting...

Node 8

You're using Node v8.17.0
The GOV.UK Prototype Kit only supports Node v16 and v18.

You can upgrade to Node v18 at https://nodejs.org/en/download

@joelanman
Copy link
Contributor

thanks, just needs a changelog

@BenSurgisonGDS
Copy link
Contributor

I'll approve once there is a changelog as Joe requested

@nataliecarey nataliecarey dismissed joelanman’s stale review May 11, 2023 15:16

I've made the requested changes.

@nataliecarey nataliecarey merged commit 39ec3fa into main May 11, 2023
@nataliecarey nataliecarey deleted the node-version-checking branch May 11, 2023 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants