Skip to content

Commit 504f519

Browse files
authored
Merge pull request #744 from adobe/bugfix/ACNA-3561
Bugfix/acna 3561
2 parents 4f7ad4f + fdf63fc commit 504f519

File tree

4 files changed

+68
-3
lines changed

4 files changed

+68
-3
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"typescript": "^5.3.3"
6262
},
6363
"engines": {
64-
"node": ">=18"
64+
"node": "^18 || ^20 || ^22"
6565
},
6666
"files": [
6767
"/bin",

src/index.js

+8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
*/
1212

1313
const { Command, run, Config } = require('@oclif/core')
14+
const semver = require('semver')
15+
const chalk = require('chalk')
1416

1517
class AIOCommand extends Command { }
1618

@@ -25,6 +27,12 @@ AIOCommand.run = async (argv, opts) => {
2527
// || module.parent && module.parent.parent && module.parent.parent.filename
2628
const config = await Config.load(opts || __dirname)
2729

30+
// Check Node.js version
31+
const nodeVersion = process.version
32+
if (!semver.satisfies(nodeVersion, config.pjson.engines.node)) {
33+
console.log(chalk.yellow(`⚠️ Warning: Node.js version ${nodeVersion} is not supported. Supported versions are ${config.pjson.engines.node}.`))
34+
}
35+
2836
// the second parameter is the root path to the CLI containing the command
2937
try {
3038
return await run(argv, config.options)

test/hookerror.test.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ jest.mock('@oclif/core', () => {
2828
Config: {
2929
load: () => {
3030
return {
31-
runHook: mockRunHook
31+
pjson: {
32+
engines: {
33+
node: '>=18 <23'
34+
}
35+
},
36+
runHook: mockRunHook,
37+
options: {}
3238
}
3339
}
3440
},

test/index.test.js

+52-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,14 @@ jest.mock('@oclif/core', () => {
1616
return {
1717
...jest.requireActual('@oclif/core'),
1818
Config: {
19-
load: () => ({})
19+
load: () => ({
20+
pjson: {
21+
engines: {
22+
node: '>=18 <23'
23+
}
24+
},
25+
options: {}
26+
})
2027
},
2128
Command: jest.fn(),
2229
run: async function (cmd) {
@@ -45,3 +52,47 @@ describe('run command', () => {
4552
process.argv = temp
4653
})
4754
})
55+
56+
describe('Node.js version check', () => {
57+
const originalVersion = process.version
58+
let logSpy
59+
60+
beforeEach(() => {
61+
logSpy = jest.spyOn(console, 'log').mockImplementation()
62+
})
63+
64+
afterEach(() => {
65+
jest.restoreAllMocks()
66+
Object.defineProperty(process, 'version', {
67+
value: originalVersion
68+
})
69+
})
70+
71+
test('should not show warning for supported Node.js version', async () => {
72+
Object.defineProperty(process, 'version', {
73+
value: 'v22.14.0'
74+
})
75+
76+
const AIOCommand = require('../src/index')
77+
await AIOCommand.run(['--version'])
78+
79+
// Check warning is not displayed
80+
expect(logSpy).not.toHaveBeenCalledWith(
81+
expect.stringContaining('Warning: Node.js version')
82+
)
83+
})
84+
85+
test('should show warning for unsupported Node.js version', async () => {
86+
Object.defineProperty(process, 'version', {
87+
value: 'v23.0.0'
88+
})
89+
90+
const AIOCommand = require('../src/index')
91+
await AIOCommand.run(['--version'])
92+
93+
// Check warning is displayed
94+
expect(logSpy).toHaveBeenCalledWith(
95+
expect.stringContaining('Warning: Node.js version v23.0.0 is not supported')
96+
)
97+
})
98+
})

0 commit comments

Comments
 (0)