From 4fdb56bfad38464388f4cbda07adc4224629ca66 Mon Sep 17 00:00:00 2001 From: Deepty Thampy Date: Fri, 11 Apr 2025 18:57:18 -0500 Subject: [PATCH 1/7] chore: add a warning when non-supported node version is used --- src/index.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/index.js b/src/index.js index 8d76e7df..d5c0c2d4 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,17 @@ 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.major(nodeVersion) > 22) { + console.log(chalk.yellow('⚠️ Warning: You are using Node.js version ' + nodeVersion + ', which is not officially supported by Adobe I/O CLI.')); + console.log(chalk.yellow(' Supported versions are Node.js 18, 20, and 22.')); + console.log(chalk.yellow(' To use a supported Node.js version, please consider using nvm (Node Version Manager).')); + console.log(chalk.yellow(' To find the nvm documentation visit:')); + console.log(chalk.yellow(' https://github.com/nvm-sh/nvm')); + console.log(); + } + // the second parameter is the root path to the CLI containing the command try { return await run(argv, config.options) From bfcb852284b1f78da67b0457379fc3ae4019533b Mon Sep 17 00:00:00 2001 From: Deepty Thampy Date: Fri, 11 Apr 2025 19:16:31 -0500 Subject: [PATCH 2/7] fix: lint error --- src/index.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/index.js b/src/index.js index d5c0c2d4..88734e50 100644 --- a/src/index.js +++ b/src/index.js @@ -11,8 +11,8 @@ */ const { Command, run, Config } = require('@oclif/core') -const semver = require('semver'); -const chalk = require('chalk'); +const semver = require('semver') +const chalk = require('chalk') class AIOCommand extends Command { } @@ -28,14 +28,14 @@ AIOCommand.run = async (argv, opts) => { const config = await Config.load(opts || __dirname) // Check Node.js version - const nodeVersion = process.version; + const nodeVersion = process.version if (semver.major(nodeVersion) > 22) { - console.log(chalk.yellow('⚠️ Warning: You are using Node.js version ' + nodeVersion + ', which is not officially supported by Adobe I/O CLI.')); - console.log(chalk.yellow(' Supported versions are Node.js 18, 20, and 22.')); - console.log(chalk.yellow(' To use a supported Node.js version, please consider using nvm (Node Version Manager).')); - console.log(chalk.yellow(' To find the nvm documentation visit:')); - console.log(chalk.yellow(' https://github.com/nvm-sh/nvm')); - console.log(); + console.log(chalk.yellow('⚠️ Warning: You are using Node.js version ' + nodeVersion + ', which is not officially supported by Adobe I/O CLI.')) + console.log(chalk.yellow(' Supported versions are Node.js 18, 20, and 22.')) + console.log(chalk.yellow(' To use a supported Node.js version, please consider using nvm (Node Version Manager).')) + console.log(chalk.yellow(' To find the nvm documentation visit:')) + console.log(chalk.yellow(' https://github.com/nvm-sh/nvm')) + console.log() } // the second parameter is the root path to the CLI containing the command From 3d23583a02907e8980b01645b85f0e6419432799 Mon Sep 17 00:00:00 2001 From: Deepty Thampy Date: Mon, 14 Apr 2025 09:30:17 -0500 Subject: [PATCH 3/7] chore: add test coverage --- test/index.test.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/test/index.test.js b/test/index.test.js index 64e9bcef..c7f7b090 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -45,3 +45,49 @@ 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 () => { + // Mock Node.js version to v22.0.0 + Object.defineProperty(process, 'version', { + value: 'v22.14.0' + }) + + const AIOCommand = require('../src/index') + await AIOCommand.run(['--version']) + + // Check that warning was not displayed + expect(logSpy).not.toHaveBeenCalledWith( + expect.stringContaining('Warning: You are using Node.js version') + ) + }) + + test('should show warning for unsupported Node.js version', async () => { + // Mock Node.js version to v23.0.0 + Object.defineProperty(process, 'version', { + value: 'v23.0.0' + }) + + const AIOCommand = require('../src/index') + await AIOCommand.run(['--version']) + + // Check that warning was displayed + expect(logSpy).toHaveBeenCalledWith( + expect.stringContaining('Warning: You are using Node.js version') + ) + }) +}) From ca030eeb75353000df07b6254cfb212e5ae651dd Mon Sep 17 00:00:00 2001 From: Deepty Thampy Date: Mon, 14 Apr 2025 09:46:06 -0500 Subject: [PATCH 4/7] fix: comments --- test/index.test.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/index.test.js b/test/index.test.js index c7f7b090..497edb17 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -62,7 +62,6 @@ describe('Node.js version check', () => { }) test('should not show warning for supported Node.js version', async () => { - // Mock Node.js version to v22.0.0 Object.defineProperty(process, 'version', { value: 'v22.14.0' }) @@ -70,14 +69,13 @@ describe('Node.js version check', () => { const AIOCommand = require('../src/index') await AIOCommand.run(['--version']) - // Check that warning was not displayed + // Check warning is not displayed expect(logSpy).not.toHaveBeenCalledWith( expect.stringContaining('Warning: You are using Node.js version') ) }) test('should show warning for unsupported Node.js version', async () => { - // Mock Node.js version to v23.0.0 Object.defineProperty(process, 'version', { value: 'v23.0.0' }) @@ -85,7 +83,7 @@ describe('Node.js version check', () => { const AIOCommand = require('../src/index') await AIOCommand.run(['--version']) - // Check that warning was displayed + // Check warning is displayed expect(logSpy).toHaveBeenCalledWith( expect.stringContaining('Warning: You are using Node.js version') ) From 5cd5315f4045d8cf605441cc2ac1ca262a2a4f2c Mon Sep 17 00:00:00 2001 From: Deepty Thampy Date: Tue, 15 Apr 2025 16:23:41 -0500 Subject: [PATCH 5/7] fix: using Config object takes care of reading and parsing the package.json file and updated unit tests --- package.json | 2 +- test/hookerror.test.js | 8 +++++++- test/index.test.js | 13 ++++++++++--- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index f32dff12..2aab0209 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "typescript": "^5.3.3" }, "engines": { - "node": ">=18" + "node": "^18 || ^20 || ^22" }, "files": [ "/bin", diff --git a/test/hookerror.test.js b/test/hookerror.test.js index 96c9c14c..e9e9e6c6 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 497edb17..31e27097 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) { @@ -71,7 +78,7 @@ describe('Node.js version check', () => { // Check warning is not displayed expect(logSpy).not.toHaveBeenCalledWith( - expect.stringContaining('Warning: You are using Node.js version') + expect.stringContaining('Warning: Node.js version') ) }) @@ -85,7 +92,7 @@ describe('Node.js version check', () => { // Check warning is displayed expect(logSpy).toHaveBeenCalledWith( - expect.stringContaining('Warning: You are using Node.js version') + expect.stringContaining('Warning: Node.js version v23.0.0 is not supported') ) }) }) From 66c3b90e90d6adc0a2699b0244ce76e81707d2c3 Mon Sep 17 00:00:00 2001 From: Deepty Thampy Date: Tue, 15 Apr 2025 16:24:33 -0500 Subject: [PATCH 6/7] fix: missed the fix --- src/index.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/index.js b/src/index.js index 88734e50..f209dae1 100644 --- a/src/index.js +++ b/src/index.js @@ -29,13 +29,8 @@ AIOCommand.run = async (argv, opts) => { // Check Node.js version const nodeVersion = process.version - if (semver.major(nodeVersion) > 22) { - console.log(chalk.yellow('⚠️ Warning: You are using Node.js version ' + nodeVersion + ', which is not officially supported by Adobe I/O CLI.')) - console.log(chalk.yellow(' Supported versions are Node.js 18, 20, and 22.')) - console.log(chalk.yellow(' To use a supported Node.js version, please consider using nvm (Node Version Manager).')) - console.log(chalk.yellow(' To find the nvm documentation visit:')) - console.log(chalk.yellow(' https://github.com/nvm-sh/nvm')) - console.log() + if (!semver.satisfies(nodeVersion, config.pjson.engines.node)) { + console.log(chalk.yellow(`⚠️ Warning: Node.js version ${nodeVersion} is not supported. Supported versions are Node.js 18, 20, and 22.`)) } // the second parameter is the root path to the CLI containing the command From fdf63fc7aa29774477f96010f0907ac51616e7dd Mon Sep 17 00:00:00 2001 From: Deepty Thampy Date: Tue, 15 Apr 2025 18:57:54 -0500 Subject: [PATCH 7/7] chore: show the supported versions from package json --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index f209dae1..e21edb1c 100644 --- a/src/index.js +++ b/src/index.js @@ -30,7 +30,7 @@ AIOCommand.run = async (argv, opts) => { // 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 Node.js 18, 20, and 22.`)) + 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