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
PR-URL: #2718
Credit: @nlf
Close: #2718
Reviewed-by: @wraithgar
  • Loading branch information
nlf committed Feb 18, 2021
1 parent af4422c commit 00afa31
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 00afa31

Please sign in to comment.