Skip to content

Commit 00afa31

Browse files
committed
restore the prefix on output from npm version <inc>
PR-URL: #2718 Credit: @nlf Close: #2718 Reviewed-by: @wraithgar
1 parent af4422c commit 00afa31

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

lib/version.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,21 @@ const version = async args => {
3737
case 0:
3838
return list()
3939
case 1:
40-
return output(await libversion(args[0], {
41-
...npm.flatOptions,
42-
path: npm.prefix,
43-
}))
40+
return version_(args)
4441
default:
4542
throw usage
4643
}
4744
}
4845

46+
const version_ = async (args) => {
47+
const prefix = npm.flatOptions.tagVersionPrefix
48+
const version = await libversion(args[0], {
49+
...npm.flatOptions,
50+
path: npm.prefix,
51+
})
52+
return output(`${prefix}${version}`)
53+
}
54+
4955
const list = async () => {
5056
const results = {}
5157
const { promisify } = require('util')

test/lib/version.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ let result = []
66
const noop = () => null
77
const npm = {
88
flatOptions: {
9+
tagVersionPrefix: 'v',
910
json: false,
1011
},
1112
prefix: '',
@@ -144,17 +145,20 @@ t.test('with one arg', t => {
144145
t.deepEqual(
145146
opts,
146147
{
148+
tagVersionPrefix: 'v',
147149
json: false,
148150
path: '',
149151
},
150152
'should forward expected options'
151153
)
152-
t.end()
154+
return '4.0.0'
153155
},
154156
})
155157

156158
version(['major'], err => {
157159
if (err)
158160
throw err
161+
t.same(result, ['v4.0.0'], 'outputs the new version prefixed by the tagVersionPrefix')
162+
t.end()
159163
})
160164
})

0 commit comments

Comments
 (0)