File tree Expand file tree Collapse file tree 3 files changed +19
-4
lines changed Expand file tree Collapse file tree 3 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ class UpdateNotifier {
2020 constructor ( options = { } ) {
2121 this . options = options ;
2222 options . pkg = options . pkg || { } ;
23+ options . distTag = options . distTag || 'latest' ;
2324
2425 // Reduce pkg to the essential keys. with fallback to deprecated options
2526 // TODO: Remove deprecated options at some point far into the future
@@ -106,12 +107,13 @@ class UpdateNotifier {
106107 }
107108
108109 async checkNpm ( ) {
109- const latest = await latestVersion ( ) ( this . packageName ) ;
110+ const { distTag} = this . options ;
111+ const latest = await latestVersion ( ) ( this . packageName , { version : distTag } ) ;
110112
111113 return {
112114 latest,
113115 current : this . packageVersion ,
114- type : semverDiff ( ) ( this . packageVersion , latest ) || 'latest' ,
116+ type : semverDiff ( ) ( this . packageVersion , latest ) || distTag ,
115117 name : this . packageName
116118 } ;
117119 }
Original file line number Diff line number Diff line change @@ -137,6 +137,13 @@ Default: `false`
137137
138138Allows notification to be shown when running as an npm script.
139139
140+ #### distTag
141+
142+ Type: ` string ` <br >
143+ Default: ` latest `
144+
145+ Which [ dist-tag] ( https://docs.npmjs.com/adding-dist-tags-to-packages ) to use to find the latest version.
146+
140147### notifier.notify([ options] )
141148
142149Convenience method to display a notification message. * (See screenshot)*
Original file line number Diff line number Diff line change @@ -13,7 +13,8 @@ const generateSettings = (options = {}) => {
1313 name : 'update-notifier-tester' ,
1414 version : '0.0.2'
1515 } ,
16- callback : options . callback
16+ callback : options . callback ,
17+ distTag : options . distTag
1718 } ;
1819} ;
1920
@@ -35,7 +36,12 @@ test.afterEach(() => {
3536
3637test ( 'check for update' , async t => {
3738 const update = await updateNotifier ( generateSettings ( ) ) . checkNpm ( ) ;
38- t . is ( update . current , '0.0.2' ) ;
39+ t . is ( update . latest , '0.0.2' ) ;
40+ } ) ;
41+
42+ test ( 'check for update with dist-tag' , async t => {
43+ const update = await updateNotifier ( generateSettings ( { distTag : '0.0.3-rc1' } ) ) . checkNpm ( ) ;
44+ t . is ( update . latest , '0.0.3-rc1' ) ;
3945} ) ;
4046
4147test . cb ( 'check for update with callback' , t => {
You can’t perform that action at this time.
0 commit comments