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

feat: use actual versions and semver.satisfies #40

Merged
merged 6 commits into from
Aug 14, 2023
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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"debug": "^4.3.3",
"envinfo": "^7.5.0",
"js-yaml": "^4.1.0",
"proxy-from-env": "^1.1.0"
"proxy-from-env": "^1.1.0",
"semver": "^7.3.7"
},
"devDependencies": {
"@adobe/eslint-config-aio-lib-config": "^2.0.1",
Expand Down
5 changes: 3 additions & 2 deletions src/commands/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const { Command, Flags } = require('@oclif/core')
const envinfo = require('envinfo')
const chalk = require('chalk')
const yaml = require('js-yaml')
const semver = require('semver')
const { getProxyForUrl } = require('proxy-from-env')

class InfoCommand extends Command {
Expand Down Expand Up @@ -119,8 +120,8 @@ class InfoCommand extends Command {
}

const nodeInfo = await envinfo.helpers.getNodeInfo()
if (!['14', '16', '18'].includes(nodeInfo[1].split('.')[0])) {
this.warn('Node version not supported. Supported versions are 14, 16, and 18')
if (!semver.satisfies(nodeInfo[1], this.config.pjson.engines.node)) {
this.warn(`Node version ${nodeInfo[1]} not supported. Supported versions are ${this.config.pjson.engines.node}`)
}
} catch (e) {
this.error(e)
Expand Down
101 changes: 92 additions & 9 deletions test/commands/info.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,20 @@ describe('instance methods', () => {

test('calls envinfo.run', () => {
command.argv = []
command.config = { pjson: { name: 'ima-cli', oclif: { plugins: [] } }, plugins: [{ name: 'name', version: 'version', type: 'type' }] }
command.config = {
pjson: {
name: 'ima-cli',
oclif: {
plugins: []
},
engines: {
node: '14 || 16 || 18'
}
},
plugins: [
{ name: 'name', version: 'version', type: 'type' }
]
}
envinfo.run.mockResolvedValue('ok')
envinfo.helpers = { getNodeInfo: () => ['', '12.5.0'] }
return command.run()
Expand Down Expand Up @@ -120,6 +133,9 @@ describe('instance methods', () => {
'core-plugin-a',
'core-plugin-b'
]
},
engines: {
node: '18'
}
},
plugins: [
Expand Down Expand Up @@ -169,6 +185,9 @@ describe('instance methods', () => {
'core-plugin-a',
'core-plugin-b'
]
},
engines: {
node: '18'
}
},
plugins: [
Expand Down Expand Up @@ -211,6 +230,9 @@ describe('instance methods', () => {
'core-plugin-b',
'core-plugin-c'
]
},
engines: {
node: '18'
}
},
plugins: [
Expand Down Expand Up @@ -282,6 +304,9 @@ describe('instance methods', () => {
'core-plugin-a',
'core-plugin-b'
]
},
engines: {
node: '18'
}
},
plugins: [
Expand Down Expand Up @@ -326,7 +351,20 @@ describe('instance methods', () => {

test('calls envinfo.run --json', () => {
command.argv = ['-j']
command.config = { pjson: { name: 'ima-cli', oclif: { plugins: [] } }, plugins: [{ name: 'name', version: 'version', type: 'type' }] }
command.config = {
pjson: {
name: 'ima-cli',
oclif: {
plugins: []
},
engines: {
node: '14 || 16 || 18'
}
},
plugins: [
{ name: 'name', version: 'version', type: 'type' }
]
}
envinfo.run.mockResolvedValue('{}')
envinfo.helpers = { getNodeInfo: () => ['', '12.5.0'] }
return command.run()
Expand All @@ -346,7 +384,20 @@ describe('instance methods', () => {

test('calls envinfo.run --yml', () => {
command.argv = ['-y']
command.config = { pjson: { name: 'ima-cli', oclif: { plugins: [] } }, plugins: [{ name: 'name', version: 'version', type: 'type' }] }
command.config = {
pjson: {
name: 'ima-cli',
oclif: {
plugins: []
},
engines: {
node: '14 || 16 || 18'
}
},
plugins: [
{ name: 'name', version: 'version', type: 'type' }
]
}
command.warn = jest.fn()
envinfo.run.mockResolvedValue('{}')
yaml.dump.mockReturnValue('yaml')
Expand Down Expand Up @@ -376,21 +427,53 @@ describe('instance methods', () => {
})

test('warns if node is not supported', async () => {
command.config = { pjson: { name: 'ima-cli', oclif: { plugins: [] } }, plugins: [{ name: 'name', version: 'version', type: 'type' }] }
command.config = {
pjson: {
name: 'ima-cli',
oclif: {
plugins: []
},
engines: {
node: '14 || 16 || 18'
}
},
plugins: [
{ name: 'name', version: 'version', type: 'type' }
]
}
command.warn = jest.fn()
envinfo.run.mockResolvedValue('{}')
envinfo.helpers = { getNodeInfo: () => ['', '13.5.0'] }
const nodeVersion = '13.5.0'
envinfo.helpers = { getNodeInfo: () => ['', nodeVersion] }
await command.run()
expect(command.warn).toHaveBeenCalledWith('Node version not supported. Supported versions are 14, 16, and 18')
expect(command.warn).toHaveBeenCalledWith(`Node version ${nodeVersion} not supported. Supported versions are ${command.config.pjson.engines.node}`)
})

test('plugins list is sorted', async () => {
command.config = { pjson: { name: 'ima-cli', oclif: { plugins: [] } }, plugins: [{ name: 'name', version: 'version', type: 'type' }, { name: 'nam', version: 'version', type: 'type' }, { name: 'name1', version: 'version', type: 'type' }] }
command.config = {
pjson: {
name: 'ima-cli',
oclif: {
plugins: []
},
engines: {
node: '14 || 16 || 18'
}
},
plugins:
[
{ name: 'name', version: 'version', type: 'type' },
{ name: 'nam', version: 'version', type: 'type' },
{ name: 'name1', version: 'version', type: 'type' }
]
}

command.warn = jest.fn()
envinfo.run.mockResolvedValue('{}')
envinfo.helpers = { getNodeInfo: () => ['', '13.5.0'] }
const nodeVersion = '13.5.0'
envinfo.helpers = { getNodeInfo: () => ['', nodeVersion] }
await command.run()
expect(command.warn).toHaveBeenCalledWith('Node version not supported. Supported versions are 14, 16, and 18')
expect(command.warn).toHaveBeenCalledWith(`Node version ${nodeVersion} not supported. Supported versions are ${command.config.pjson.engines.node}`)
})
})
})