Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update notifier to consider engine range #8050

Draft
wants to merge 1 commit into
base: latest
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/cli/update-notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const updateCheck = async (npm, spec, version, current) => {
// and should get the updates from that release train.
// Note that this isn't another http request over the network, because
// the packument will be cached by pacote from previous request.
if (gt(version, latest) && spec === 'latest') {
if (gt(version, latest) && spec === '*') {
return updateNotifier(npm, `^${version}`)
}

Expand Down Expand Up @@ -71,7 +71,7 @@ const updateCheck = async (npm, spec, version, current) => {
return message
}

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

// while on a beta train, get updates daily
const duration = spec !== 'latest' ? DAILY : WEEKLY
const duration = current.prerelease.length ? DAILY : WEEKLY
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't have been changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be wrong here, but my understanding was since we are using * as spec in new change it will always be !== 'latest' in that case, and what i understood from the existing logic is we are calculating duration as DAILY for pre release version so simplified it to that.

Copy link
Member

@wraithgar wraithgar Jan 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! I got this patch backwards. You added the prerelease check. This was the right decision.


const t = new Date(Date.now() - duration)
// if we don't have a file, then definitely check it.
Expand Down
24 changes: 12 additions & 12 deletions test/lib/cli/update-notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const runUpdateNotifier = async (t, {
if (PACOTE_ERROR) {
throw PACOTE_ERROR
}
const manifestV = spec === 'npm@latest' ? CURRENT_VERSION
const manifestV = spec === 'npm@*' ? CURRENT_VERSION
: /-/.test(spec) ? CURRENT_BETA : NEXT_VERSION
return { version: manifestV }
},
Expand Down Expand Up @@ -127,7 +127,7 @@ t.test('situations in which we do not notify', t => {
const { wroteFile, result, MANIFEST_REQUEST } = await runUpdateNotifier(t, {
command: 'install',
prefixDir: { 'package.json': `{"name":"${t.testName}"}` },
argv: ['npm@latest'],
argv: ['npm@*'],
global: true,
})
t.equal(wroteFile, false)
Expand All @@ -139,28 +139,28 @@ t.test('situations in which we do not notify', t => {
const { wroteFile, result, MANIFEST_REQUEST } = await runUpdateNotifier(t)
t.equal(wroteFile, true)
t.equal(result, null)
t.strictSame(MANIFEST_REQUEST, ['npm@latest'], 'requested latest version')
t.strictSame(MANIFEST_REQUEST, ['npm@*'], 'requested latest version')
})
t.test('check if stat errors (here for coverage)', async t => {
const STAT_ERROR = new Error('blorg')
const { wroteFile, result, MANIFEST_REQUEST } = await runUpdateNotifier(t, { STAT_ERROR })
t.equal(wroteFile, true)
t.equal(result, null)
t.strictSame(MANIFEST_REQUEST, ['npm@latest'], 'requested latest version')
t.strictSame(MANIFEST_REQUEST, ['npm@*'], 'requested latest version')
})
t.test('ok if write errors (here for coverage)', async t => {
const WRITE_ERROR = new Error('grolb')
const { wroteFile, result, MANIFEST_REQUEST } = await runUpdateNotifier(t, { WRITE_ERROR })
t.equal(wroteFile, true)
t.equal(result, null)
t.strictSame(MANIFEST_REQUEST, ['npm@latest'], 'requested latest version')
t.strictSame(MANIFEST_REQUEST, ['npm@*'], 'requested latest version')
})
t.test('ignore pacote failures (here for coverage)', async t => {
const PACOTE_ERROR = new Error('pah-KO-tchay')
const { wroteFile, result, MANIFEST_REQUEST } = await runUpdateNotifier(t, { PACOTE_ERROR })
t.equal(result, null)
t.equal(wroteFile, true)
t.strictSame(MANIFEST_REQUEST, ['npm@latest'], 'requested latest version')
t.strictSame(MANIFEST_REQUEST, ['npm@*'], 'requested latest version')
})
t.test('do not update if newer than latest, but same as next', async t => {
const {
Expand All @@ -170,7 +170,7 @@ t.test('situations in which we do not notify', t => {
} = await runUpdateNotifier(t, { version: NEXT_VERSION })
t.equal(result, null)
t.equal(wroteFile, true)
const reqs = ['npm@latest', `npm@^${NEXT_VERSION}`]
const reqs = ['npm@*', `npm@^${NEXT_VERSION}`]
t.strictSame(MANIFEST_REQUEST, reqs, 'requested latest and next versions')
})
t.test('do not update if on the latest beta', async t => {
Expand Down Expand Up @@ -222,11 +222,11 @@ t.test('situations in which we do not notify', t => {
t.test('notification situations', async t => {
const cases = {
[HAVE_BETA]: [`^{V}`],
[NEXT_PATCH]: [`latest`, `^{V}`],
[NEXT_MINOR]: [`latest`, `^{V}`],
[CURRENT_PATCH]: ['latest'],
[CURRENT_MINOR]: ['latest'],
[CURRENT_MAJOR]: ['latest'],
[NEXT_PATCH]: [`*`, `^{V}`],
[NEXT_MINOR]: [`*`, `^{V}`],
[CURRENT_PATCH]: ['*'],
[CURRENT_MINOR]: ['*'],
[CURRENT_MAJOR]: ['*'],
}

for (const [version, reqs] of Object.entries(cases)) {
Expand Down
Loading