Skip to content

Commit

Permalink
fix: use includePrerelease flag when checking node version
Browse files Browse the repository at this point in the history
The code stripping it out predates that flag even existing in node-semver
  • Loading branch information
wraithgar committed Jun 19, 2023
1 parent d980405 commit 0b8902e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/cli-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = async (process, validateEngines) => {
process.on('unhandledRejection', exitHandler)

// It is now safe to log a warning if they are using a version of node that is not going to fail on syntax errors but is still unsupported and untested and might not work reliably. This is safe to use the logger now which we want since this will show up in the error log too.
if (!satisfies(validateEngines.node, validateEngines.engines)) {
if (!satisfies(validateEngines.node, validateEngines.engines, { includePrerelease: true })) {
log.warn('cli', validateEngines.unsupportedMessage)
}

Expand Down
2 changes: 1 addition & 1 deletion lib/es6/validate-engines.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const { engines: { node: engines }, version } = require('../../package.json')
const npm = `v${version}`

module.exports = (process, getCli) => {
const node = process.version.replace(/-.*$/, '')
const node = process.version

/* eslint-disable-next-line max-len */
const unsupportedMessage = `npm ${npm} does not support Node.js ${node}. This version of npm supports the following node versions: \`${engines}\`. You can find the latest version at https://nodejs.org/.`
Expand Down
10 changes: 10 additions & 0 deletions test/lib/cli-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,13 @@ t.test('unsupported node version', async t => {
/npm v.* does not support Node\.js 12\.6\.0\./
)
})

t.test('node prerelease is supported inside engines', async t => {
const { cli, logs } = await cliMock(t, {
globals: {
'process.version': `${process.version}-pre.0`,
},
})
await cli(process)
t.notMatch(logs.warn[0], [])
})

0 comments on commit 0b8902e

Please sign in to comment.