diff --git a/README.md b/README.md index 915e93c..0bcd301 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ $ npm install -g @adobe/aio-cli $ aio COMMAND running command... $ aio (--version|-v) -@adobe/aio-cli/10.3.3 darwin-arm64 node-v20.18.2 +@adobe/aio-cli/10.3.4 darwin-arm64 node-v20.18.2 $ aio --help [COMMAND] USAGE $ aio COMMAND @@ -3438,7 +3438,7 @@ ALIASES $ aio plugins discover ``` -_See code: [src/commands/discover.ts](https://github.com/adobe/aio-cli/blob/10.3.3/src/commands/discover.ts)_ +_See code: [src/commands/discover.ts](https://github.com/adobe/aio-cli/blob/10.3.4/src/commands/discover.ts)_ ## `aio event` @@ -4600,7 +4600,7 @@ DESCRIPTION Clears all installed plugins. ``` -_See code: [src/commands/rollback.ts](https://github.com/adobe/aio-cli/blob/10.3.3/src/commands/rollback.ts)_ +_See code: [src/commands/rollback.ts](https://github.com/adobe/aio-cli/blob/10.3.4/src/commands/rollback.ts)_ ## `aio rt` @@ -13846,7 +13846,7 @@ DESCRIPTION - update user-installed plugins that are not core ``` -_See code: [src/commands/update.ts](https://github.com/adobe/aio-cli/blob/10.3.3/src/commands/update.ts)_ +_See code: [src/commands/update.ts](https://github.com/adobe/aio-cli/blob/10.3.4/src/commands/update.ts)_ ## `aio where` diff --git a/package-lock.json b/package-lock.json index 00394d8..0f9594a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@adobe/aio-cli", - "version": "10.3.3", + "version": "10.3.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@adobe/aio-cli", - "version": "10.3.3", + "version": "10.3.4", "license": "Apache-2.0", "dependencies": { "@adobe/aio-cli-plugin-app": "^13", diff --git a/package.json b/package.json index f32dff1..26cb5c8 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@adobe/aio-cli", "description": "Adobe I/O Extensible CLI\n\n******* *******\n****** ******\n***** *****\n**** * ****\n*** *** ***\n** ***** **\n* ** *\n", - "version": "10.3.3", + "version": "10.3.4", "author": "Adobe Inc.", "bin": { "aio": "bin/run" @@ -61,7 +61,7 @@ "typescript": "^5.3.3" }, "engines": { - "node": ">=18" + "node": "^18 || ^20 || ^22" }, "files": [ "/bin", diff --git a/src/index.js b/src/index.js index 8d76e7d..e21edb1 100644 --- a/src/index.js +++ b/src/index.js @@ -11,6 +11,8 @@ */ const { Command, run, Config } = require('@oclif/core') +const semver = require('semver') +const chalk = require('chalk') class AIOCommand extends Command { } @@ -25,6 +27,12 @@ AIOCommand.run = async (argv, opts) => { // || module.parent && module.parent.parent && module.parent.parent.filename const config = await Config.load(opts || __dirname) + // Check Node.js version + const nodeVersion = process.version + if (!semver.satisfies(nodeVersion, config.pjson.engines.node)) { + console.log(chalk.yellow(`⚠️ Warning: Node.js version ${nodeVersion} is not supported. Supported versions are ${config.pjson.engines.node}.`)) + } + // the second parameter is the root path to the CLI containing the command try { return await run(argv, config.options) diff --git a/test/hookerror.test.js b/test/hookerror.test.js index 96c9c14..e9e9e6c 100644 --- a/test/hookerror.test.js +++ b/test/hookerror.test.js @@ -28,7 +28,13 @@ jest.mock('@oclif/core', () => { Config: { load: () => { return { - runHook: mockRunHook + pjson: { + engines: { + node: '>=18 <23' + } + }, + runHook: mockRunHook, + options: {} } } }, diff --git a/test/index.test.js b/test/index.test.js index 64e9bce..31e2709 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -16,7 +16,14 @@ jest.mock('@oclif/core', () => { return { ...jest.requireActual('@oclif/core'), Config: { - load: () => ({}) + load: () => ({ + pjson: { + engines: { + node: '>=18 <23' + } + }, + options: {} + }) }, Command: jest.fn(), run: async function (cmd) { @@ -45,3 +52,47 @@ describe('run command', () => { process.argv = temp }) }) + +describe('Node.js version check', () => { + const originalVersion = process.version + let logSpy + + beforeEach(() => { + logSpy = jest.spyOn(console, 'log').mockImplementation() + }) + + afterEach(() => { + jest.restoreAllMocks() + Object.defineProperty(process, 'version', { + value: originalVersion + }) + }) + + test('should not show warning for supported Node.js version', async () => { + Object.defineProperty(process, 'version', { + value: 'v22.14.0' + }) + + const AIOCommand = require('../src/index') + await AIOCommand.run(['--version']) + + // Check warning is not displayed + expect(logSpy).not.toHaveBeenCalledWith( + expect.stringContaining('Warning: Node.js version') + ) + }) + + test('should show warning for unsupported Node.js version', async () => { + Object.defineProperty(process, 'version', { + value: 'v23.0.0' + }) + + const AIOCommand = require('../src/index') + await AIOCommand.run(['--version']) + + // Check warning is displayed + expect(logSpy).toHaveBeenCalledWith( + expect.stringContaining('Warning: Node.js version v23.0.0 is not supported') + ) + }) +})