Skip to content

Commit

Permalink
fix: skip update notifier file if not requested
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys authored and fritzy committed Apr 13, 2022
1 parent 877138e commit 3f7fe17
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/utils/update-notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const stat = promisify(require('fs').stat)
const writeFile = promisify(require('fs').writeFile)
const { resolve } = require('path')

const SKIP = Symbol('SKIP')

const isGlobalNpmUpdate = npm => {
return npm.flatOptions.global &&
['install', 'update'].includes(npm.command) &&
Expand Down Expand Up @@ -38,7 +40,7 @@ const updateNotifier = async (npm, spec = 'latest') => {
if (!npm.config.get('update-notifier') ||
isGlobalNpmUpdate(npm) ||
ciDetect()) {
return null
return SKIP
}

// if we're on a prerelease train, then updates are coming fast
Expand Down Expand Up @@ -118,6 +120,12 @@ const updateNotifier = async (npm, spec = 'latest') => {
// only update the notification timeout if we actually finished checking
module.exports = async npm => {
const notification = await updateNotifier(npm)

// dont write the file if we skipped checking altogether
if (notification === SKIP) {
return null
}

// intentional. do not await this. it's a best-effort update. if this
// fails, it's ok. might be using /dev/null as the cache or something weird
// like that.
Expand Down

0 comments on commit 3f7fe17

Please sign in to comment.