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

Fix minimum version for CLIs #2292

Merged
merged 7 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/create-snap/src/cmds/init/initHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ describe('initialize', () => {
};

await expect(initHandler({ ...getMockArgv() })).rejects.toThrow(
`Init Error: You are using an outdated version of Node (${process.version}). Please update to Node >=18.6.0.`,
`Init Error: You are using an outdated version of Node (${process.version}). Please update to Node >=18.16.0.`,
);
});

Expand Down
2 changes: 1 addition & 1 deletion packages/create-snap/src/cmds/init/initHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
yarnInstall,
} from './initUtils';

const SATISFIED_VERSION = '>=18.6.0' as SemVerRange;
const SATISFIED_VERSION = '>=18.16.0' as SemVerRange;

/**
* Creates a new snap package, based on one of the provided templates. This
Expand Down
27 changes: 4 additions & 23 deletions packages/snaps-cli/src/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const getMockArgv = (...args: string[]) => {
const HELP_TEXT_REGEX = /^\s*Usage: .+ <command> \[options\]/u;

describe('checkNodeVersion', () => {
it.each(['16.17.0', '16.18.0', '18.6.0', '18.7.0', '20.0.0'])(
it.each(['18.16.0', '18.17.0', '20.0.0'])(
'does not exit if the Node version is %s',
(version) => {
const spy = jest.spyOn(process, 'exit').mockImplementation();
Expand All @@ -38,8 +38,8 @@ describe('checkNodeVersion', () => {
},
);

it.each(['14.0.0', '16.0.0', '16.16.1'])(
'logs a message and exists if the Node version is %s',
it.each(['14.0.0', '16.0.0', '16.16.1', '18.0.0', '18.5.0'])(
'logs a message and exits if the Node version is %s',
(version) => {
const spy = jest.spyOn(process, 'exit').mockImplementation();
const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation();
Expand All @@ -51,26 +51,7 @@ describe('checkNodeVersion', () => {
expect(consoleErrorSpy).toHaveBeenCalledTimes(1);
expect(consoleErrorSpy).toHaveBeenCalledWith(
expect.stringContaining(
`Node version ${version} is not supported. Please use Node 16.17.0 or later.`,
),
);
},
);

it.each(['18.0.0', '18.5.0'])(
'logs a message and exists if the Node version is %s',
(version) => {
const spy = jest.spyOn(process, 'exit').mockImplementation();
const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation();

checkNodeVersion(version);

expect(spy).toHaveBeenCalledTimes(1);
expect(spy).toHaveBeenCalledWith(1);
expect(consoleErrorSpy).toHaveBeenCalledTimes(1);
expect(consoleErrorSpy).toHaveBeenCalledWith(
expect.stringContaining(
`Node version ${version} is not supported. Please use Node 18.6.0 or later.`,
`Node version ${version} is not supported. Please use Node 18.16.0 or later.`,
),
);
},
Expand Down
15 changes: 3 additions & 12 deletions packages/snaps-cli/src/cli.ts
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import builders from './builders';
import { getConfigByArgv } from './config';
import { error, getYargsErrorMessage, sanitizeInputs } from './utils';

const MINIMUM_NODE_16_VERSION = '16.17.0';
const MINIMUM_NODE_18_VERSION = '18.6.0';
const MINIMUM_NODE_18_VERSION = '18.16.0';

/**
* Check the Node version. If the Node version is less than the minimum required
Expand All @@ -19,17 +18,9 @@ export function checkNodeVersion(
nodeVersion: string = process.version.slice(1),
) {
const majorVersion = semver.major(nodeVersion);
const message = `Node version ${nodeVersion} is not supported. Please use Node ${MINIMUM_NODE_16_VERSION} or later.`;
const message = `Node version ${nodeVersion} is not supported. Please use Node ${MINIMUM_NODE_18_VERSION} or later.`;

if (majorVersion < 16) {
error(message);
// eslint-disable-next-line n/no-process-exit
process.exit(1);
}

// Node 16 and 18 have a different minimum version requirement, so we need to
// check for both.
if (majorVersion === 16 && semver.lt(nodeVersion, MINIMUM_NODE_16_VERSION)) {
if (majorVersion < 18) {
error(message);
// eslint-disable-next-line n/no-process-exit
process.exit(1);
Expand Down
Loading