Skip to content

Commit f95e421

Browse files
committed
fix: update notifier to consider engine range
1 parent dc31c1b commit f95e421

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

lib/cli/update-notifier.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const updateCheck = async (npm, spec, version, current) => {
4040
// and should get the updates from that release train.
4141
// Note that this isn't another http request over the network, because
4242
// the packument will be cached by pacote from previous request.
43-
if (gt(version, latest) && spec === 'latest') {
43+
if (gt(version, latest) && spec === '*') {
4444
return updateNotifier(npm, `^${version}`)
4545
}
4646

@@ -71,7 +71,7 @@ const updateCheck = async (npm, spec, version, current) => {
7171
return message
7272
}
7373

74-
const updateNotifier = async (npm, spec = 'latest') => {
74+
const updateNotifier = async (npm, spec = '*') => {
7575
// if we're on a prerelease train, then updates are coming fast
7676
// check for a new one daily. otherwise, weekly.
7777
const { version } = npm
@@ -83,7 +83,7 @@ const updateNotifier = async (npm, spec = 'latest') => {
8383
}
8484

8585
// while on a beta train, get updates daily
86-
const duration = spec !== 'latest' ? DAILY : WEEKLY
86+
const duration = current.prerelease.length ? DAILY : WEEKLY
8787

8888
const t = new Date(Date.now() - duration)
8989
// if we don't have a file, then definitely check it.

test/lib/cli/update-notifier.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const runUpdateNotifier = async (t, {
6161
if (PACOTE_ERROR) {
6262
throw PACOTE_ERROR
6363
}
64-
const manifestV = spec === 'npm@latest' ? CURRENT_VERSION
64+
const manifestV = spec === 'npm@*' ? CURRENT_VERSION
6565
: /-/.test(spec) ? CURRENT_BETA : NEXT_VERSION
6666
return { version: manifestV }
6767
},
@@ -127,7 +127,7 @@ t.test('situations in which we do not notify', t => {
127127
const { wroteFile, result, MANIFEST_REQUEST } = await runUpdateNotifier(t, {
128128
command: 'install',
129129
prefixDir: { 'package.json': `{"name":"${t.testName}"}` },
130-
argv: ['npm@latest'],
130+
argv: ['npm@*'],
131131
global: true,
132132
})
133133
t.equal(wroteFile, false)
@@ -139,28 +139,28 @@ t.test('situations in which we do not notify', t => {
139139
const { wroteFile, result, MANIFEST_REQUEST } = await runUpdateNotifier(t)
140140
t.equal(wroteFile, true)
141141
t.equal(result, null)
142-
t.strictSame(MANIFEST_REQUEST, ['npm@latest'], 'requested latest version')
142+
t.strictSame(MANIFEST_REQUEST, ['npm@*'], 'requested latest version')
143143
})
144144
t.test('check if stat errors (here for coverage)', async t => {
145145
const STAT_ERROR = new Error('blorg')
146146
const { wroteFile, result, MANIFEST_REQUEST } = await runUpdateNotifier(t, { STAT_ERROR })
147147
t.equal(wroteFile, true)
148148
t.equal(result, null)
149-
t.strictSame(MANIFEST_REQUEST, ['npm@latest'], 'requested latest version')
149+
t.strictSame(MANIFEST_REQUEST, ['npm@*'], 'requested latest version')
150150
})
151151
t.test('ok if write errors (here for coverage)', async t => {
152152
const WRITE_ERROR = new Error('grolb')
153153
const { wroteFile, result, MANIFEST_REQUEST } = await runUpdateNotifier(t, { WRITE_ERROR })
154154
t.equal(wroteFile, true)
155155
t.equal(result, null)
156-
t.strictSame(MANIFEST_REQUEST, ['npm@latest'], 'requested latest version')
156+
t.strictSame(MANIFEST_REQUEST, ['npm@*'], 'requested latest version')
157157
})
158158
t.test('ignore pacote failures (here for coverage)', async t => {
159159
const PACOTE_ERROR = new Error('pah-KO-tchay')
160160
const { wroteFile, result, MANIFEST_REQUEST } = await runUpdateNotifier(t, { PACOTE_ERROR })
161161
t.equal(result, null)
162162
t.equal(wroteFile, true)
163-
t.strictSame(MANIFEST_REQUEST, ['npm@latest'], 'requested latest version')
163+
t.strictSame(MANIFEST_REQUEST, ['npm@*'], 'requested latest version')
164164
})
165165
t.test('do not update if newer than latest, but same as next', async t => {
166166
const {
@@ -170,7 +170,7 @@ t.test('situations in which we do not notify', t => {
170170
} = await runUpdateNotifier(t, { version: NEXT_VERSION })
171171
t.equal(result, null)
172172
t.equal(wroteFile, true)
173-
const reqs = ['npm@latest', `npm@^${NEXT_VERSION}`]
173+
const reqs = ['npm@*', `npm@^${NEXT_VERSION}`]
174174
t.strictSame(MANIFEST_REQUEST, reqs, 'requested latest and next versions')
175175
})
176176
t.test('do not update if on the latest beta', async t => {
@@ -222,11 +222,11 @@ t.test('situations in which we do not notify', t => {
222222
t.test('notification situations', async t => {
223223
const cases = {
224224
[HAVE_BETA]: [`^{V}`],
225-
[NEXT_PATCH]: [`latest`, `^{V}`],
226-
[NEXT_MINOR]: [`latest`, `^{V}`],
227-
[CURRENT_PATCH]: ['latest'],
228-
[CURRENT_MINOR]: ['latest'],
229-
[CURRENT_MAJOR]: ['latest'],
225+
[NEXT_PATCH]: [`*`, `^{V}`],
226+
[NEXT_MINOR]: [`*`, `^{V}`],
227+
[CURRENT_PATCH]: ['*'],
228+
[CURRENT_MINOR]: ['*'],
229+
[CURRENT_MAJOR]: ['*'],
230230
}
231231

232232
for (const [version, reqs] of Object.entries(cases)) {

0 commit comments

Comments
 (0)