Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"typescript": "^5.3.3"
},
"engines": {
"node": ">=18"
"node": "^18 || ^20 || ^22"
},
"files": [
"/bin",
Expand Down
8 changes: 8 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
*/

const { Command, run, Config } = require('@oclif/core')
const semver = require('semver')
const chalk = require('chalk')

class AIOCommand extends Command { }

Expand All @@ -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)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it too geeky to output this?
Supported versions are ${config.pjson.engines.node}.
Then we would just have to update package.json and not look at this again :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that. But wasn't sure if its ok to show the versions from package json. Made the change though
Screenshot 2025-04-15 at 6 58 24 PM

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)
Expand Down
8 changes: 7 additions & 1 deletion test/hookerror.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ jest.mock('@oclif/core', () => {
Config: {
load: () => {
return {
runHook: mockRunHook
pjson: {
engines: {
node: '>=18 <23'
}
},
runHook: mockRunHook,
options: {}
}
}
},
Expand Down
53 changes: 52 additions & 1 deletion test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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')
)
})
})