Skip to content

Commit

Permalink
restore the prefix on output from npm version <inc>
Browse files Browse the repository at this point in the history
  • Loading branch information
nlf committed Feb 17, 2021
1 parent e703362 commit b4dcaa0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
14 changes: 10 additions & 4 deletions lib/version.js
Expand Up @@ -37,15 +37,21 @@ const version = async args => {
case 0:
return list()
case 1:
return output(await libversion(args[0], {
...npm.flatOptions,
path: npm.prefix,
}))
return version_(args)
default:
throw usage
}
}

const version_ = async (args) => {
const prefix = npm.flatOptions.tagVersionPrefix
const version = await libversion(args[0], {
...npm.flatOptions,
path: npm.prefix,
})
return output(`${prefix}${version}`)
}

const list = async () => {
const results = {}
const { promisify } = require('util')
Expand Down
6 changes: 5 additions & 1 deletion test/lib/version.js
Expand Up @@ -6,6 +6,7 @@ let result = []
const noop = () => null
const npm = {
flatOptions: {
tagVersionPrefix: 'v',
json: false,
},
prefix: '',
Expand Down Expand Up @@ -144,17 +145,20 @@ t.test('with one arg', t => {
t.deepEqual(
opts,
{
tagVersionPrefix: 'v',
json: false,
path: '',
},
'should forward expected options'
)
t.end()
return '4.0.0'
},
})

version(['major'], err => {
if (err)
throw err
t.same(result, ['v4.0.0'], 'outputs the new version prefixed by the tagVersionPrefix')
t.end()
})
})

0 comments on commit b4dcaa0

Please sign in to comment.