Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: sindresorhus/update-notifier
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: adf7af05330704fa43b7658ff4b3b168428d0eab
Choose a base ref
...
head repository: sindresorhus/update-notifier
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 311557ec77dbb35ea130530639b0da7bbb254897
Choose a head ref

Commits on Jul 12, 2017

  1. Update chalk to 2.0.1 (#117)

    develar authored and sindresorhus committed Jul 12, 2017
    Copy the full SHA
    4bfb8b4 View commit details

Commits on Sep 29, 2017

  1. Move to AVA for testing (#121)

    timdeschryver authored and sindresorhus committed Sep 29, 2017
    Copy the full SHA
    6f2b074 View commit details
  2. Meta tweaks

    sindresorhus committed Sep 29, 2017
    Copy the full SHA
    6008ccf View commit details

Commits on Oct 9, 2017

  1. Copy the full SHA
    97d0b97 View commit details
  2. Copy the full SHA
    70b8248 View commit details
  3. Force bump boxen dependency

    Fixes #125
    sindresorhus committed Oct 9, 2017
    Copy the full SHA
    3eaa793 View commit details
  4. 2.3.0

    sindresorhus committed Oct 9, 2017
    Copy the full SHA
    492c21e View commit details

Commits on Oct 23, 2017

  1. Fix typo in README (#128)

    meain authored and SBoudrias committed Oct 23, 2017
    Copy the full SHA
    3e5cea0 View commit details

Commits on Oct 30, 2017

  1. Disable on CI (#116)

    SimenB authored and sindresorhus committed Oct 30, 2017
    Copy the full SHA
    38d5679 View commit details

Commits on Feb 14, 2018

  1. Update URL to XO

    sindresorhus committed Feb 14, 2018
    Copy the full SHA
    0ad8e5b View commit details

Commits on Mar 13, 2018

  1. Fix URI Scheme in package.json (#136)

    willnode authored and SBoudrias committed Mar 13, 2018
    Copy the full SHA
    accc884 View commit details

Commits on Mar 25, 2018

  1. Add license file

    sindresorhus committed Mar 25, 2018
    Copy the full SHA
    83c4daa View commit details
  2. 2.4.0

    sindresorhus committed Mar 25, 2018
    Copy the full SHA
    edbe3d2 View commit details

Commits on Apr 14, 2018

  1. Add ability to bypass isNpm check with shouldNotifyInNpmScript opti…

    …on (#127)
    
    * Added ability to bypass isNpm with 'shouldNotifyInNpmScript' option
    
    * Updated readme with option
    
    * Fixed grammatical error in readme
    
    * Rename skipIsNpmCheck to shouldNotifyInNpmScript
    
    * Refactored test to use renamed shouldNotifyInNpmScript property
    alexccl authored and SBoudrias committed Apr 14, 2018
    1
    Copy the full SHA
    ac0d3cb View commit details
  2. 2.5.0

    SBoudrias committed Apr 14, 2018
    Copy the full SHA
    5cd6577 View commit details

Commits on May 13, 2018

  1. Docs: isGlobal option does not default to true (#142)

    The value has been auto-detected since #114
    dideler authored and SBoudrias committed May 13, 2018
    Copy the full SHA
    d371834 View commit details

Commits on Sep 12, 2018

  1. Copy the full SHA
    8df01b3 View commit details

Commits on Mar 28, 2019

  1. Copy the full SHA
    0d49f51 View commit details
  2. Require Node.js 8

    sindresorhus committed Mar 28, 2019
    Copy the full SHA
    aafd8a0 View commit details

Commits on Apr 7, 2019

  1. Add failing test for #153 (#154)

    LitoMore authored and sindresorhus committed Apr 7, 2019
    Copy the full SHA
    14632e4 View commit details
  2. Add distTag option (#151)

    LitoMore authored and sindresorhus committed Apr 7, 2019
    Copy the full SHA
    c8faa84 View commit details

Commits on Apr 12, 2019

  1. Fix failing test (#155)

    LitoMore authored and SBoudrias committed Apr 12, 2019
    Copy the full SHA
    79e89ad View commit details

Commits on Apr 19, 2019

  1. Copy the full SHA
    5f06620 View commit details

Commits on May 10, 2019

  1. Copy the full SHA
    ad8ed1b View commit details
  2. 3.0.0

    SBoudrias committed May 10, 2019
    Copy the full SHA
    a7bb3ee View commit details

Commits on May 25, 2019

  1. Create funding.yml

    sindresorhus committed May 25, 2019
    Copy the full SHA
    72f83d1 View commit details

Commits on May 31, 2019

  1. Tidelift tasks

    sindresorhus committed May 31, 2019
    Copy the full SHA
    1712928 View commit details

Commits on Jul 2, 2019

  1. Copy the full SHA
    f9d168a View commit details
  2. Update URL to TTY (#163)

    ecmarsh authored and SBoudrias committed Jul 2, 2019
    Copy the full SHA
    a6d6b49 View commit details
  3. Update Travis matrix

    SBoudrias committed Jul 2, 2019
    Copy the full SHA
    f8b4e60 View commit details
  4. 3.0.1

    SBoudrias committed Jul 2, 2019
    Copy the full SHA
    592b025 View commit details

Commits on Jul 14, 2019

  1. Copy the full SHA
    bf73119 View commit details

Commits on Dec 12, 2019

  1. Disable when NODE_ENV is test (#173)

    ehmicky authored and sindresorhus committed Dec 12, 2019
    Copy the full SHA
    b1525e6 View commit details
  2. Update dependencies

    sindresorhus committed Dec 12, 2019
    Copy the full SHA
    ccaf686 View commit details
  3. Copy the full SHA
    bc1721a View commit details
  4. Copy the full SHA
    39682de View commit details
  5. Remove the callback option (#158)

    LitoMore authored and sindresorhus committed Dec 12, 2019
    Copy the full SHA
    fb5161c View commit details
  6. 4.0.0

    sindresorhus committed Dec 12, 2019
    Copy the full SHA
    adf7803 View commit details

Commits on Feb 14, 2020

  1. Add template support for the message option (#175)

    Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
    fisker and sindresorhus authored Feb 14, 2020
    Copy the full SHA
    adbeb6e View commit details
  2. Update dependencies

    sindresorhus committed Feb 14, 2020
    Copy the full SHA
    4062f12 View commit details
  3. 4.1.0

    sindresorhus committed Feb 14, 2020
    Copy the full SHA
    9d9f4ff View commit details
  4. Fix Travis

    sindresorhus committed Feb 14, 2020
    Copy the full SHA
    64c5236 View commit details

Commits on Apr 19, 2020

  1. Use HTTPS links

    sindresorhus committed Apr 19, 2020
    Copy the full SHA
    71a3f19 View commit details

Commits on Aug 16, 2020

  1. Copy the full SHA
    f42fc8f View commit details
  2. 4.1.1

    sindresorhus committed Aug 16, 2020
    Copy the full SHA
    c9d2166 View commit details

Commits on Sep 16, 2020

  1. Copy the full SHA
    132b7ce View commit details

Commits on Sep 29, 2020

  1. Copy the full SHA
    3dfe42d View commit details
  2. Require Node.js 10

    sindresorhus committed Sep 29, 2020
    Copy the full SHA
    5b440c2 View commit details
  3. 5.0.0

    sindresorhus committed Sep 29, 2020
    Copy the full SHA
    da7c464 View commit details

Commits on Nov 1, 2020

  1. Update dependencies

    sindresorhus committed Nov 1, 2020
    Copy the full SHA
    9e2b772 View commit details
Showing with 640 additions and 423 deletions.
  1. +1 −2 .gitattributes
  2. +2 −0 .github/funding.yml
  3. +3 −0 .github/security.md
  4. +22 −0 .github/workflows/main.yml
  5. +2 −1 .gitignore
  6. +1 −0 .npmrc
  7. +0 −4 .travis.yml
  8. +13 −9 check.js
  9. +1 −1 contributing.md
  10. +5 −5 example.js
  11. +3 −146 index.js
  12. +9 −0 license
  13. +65 −50 package.json
  14. +90 −43 readme.md
  15. +0 −162 test.js
  16. +20 −0 test/fs-error.js
  17. +147 −0 test/notify.js
  18. +63 −0 test/update-notifier.js
  19. +193 −0 update-notifier.js
3 changes: 1 addition & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
* text=auto
*.js text eol=lf
* text=auto eol=lf
2 changes: 2 additions & 0 deletions .github/funding.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github: sindresorhus
tidelift: npm/update-notifier
3 changes: 3 additions & 0 deletions .github/security.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Security Policy

To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure.
22 changes: 22 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: CI
on:
- push
- pull_request
jobs:
test:
name: Node.js ${{ matrix.node-version }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version:
- 18
- 16
- 14
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules
yarn.lock
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
4 changes: 0 additions & 4 deletions .travis.yml

This file was deleted.

22 changes: 13 additions & 9 deletions check.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
/* eslint-disable unicorn/no-process-exit */
'use strict';
let updateNotifier = require('.');
import process from 'node:process';
import UpdateNotifier from './update-notifier.js';

const options = JSON.parse(process.argv[2]);
const updateNotifier = new UpdateNotifier(JSON.parse(process.argv[2]));

updateNotifier = new updateNotifier.UpdateNotifier(options);
try {
// Exit process when offline
setTimeout(process.exit, 1000 * 30);

const update = await updateNotifier.fetchInfo();

updateNotifier.checkNpm().then(update => {
// Only update the last update check time on success
updateNotifier.config.set('lastUpdateCheck', Date.now());

if (update.type && update.type !== 'latest') {
updateNotifier.config.set('update', update);
}

// Call process exit explicitly to terminate the child process
// Otherwise the child process will run forever, according to the Node.js docs
// Call process exit explicitly to terminate the child process,
// otherwise the child process will run forever, according to the Node.js docs
process.exit();
}).catch(() => {
} catch (error) {
console.error(error);
process.exit(1);
});
}
2 changes: 1 addition & 1 deletion contributing.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
See the [contributing docs](https://github.com/yeoman/yeoman/blob/master/contributing.md)
See the [contributing docs](https://github.com/yeoman/yeoman/blob/main/contributing.md)
10 changes: 5 additions & 5 deletions example.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict';
const updateNotifier = require('.');
import updateNotifier from './index.js';

// Run: $ node example

@@ -10,7 +9,8 @@ const updateNotifier = require('.');
updateNotifier({
pkg: {
name: 'public-ip',
version: '0.9.2'
version: '0.9.2',
},
updateCheckInterval: 0
}).notify();
updateCheckInterval: 0,
})
.notify();
149 changes: 3 additions & 146 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,150 +1,7 @@
'use strict';
const spawn = require('child_process').spawn;
const path = require('path');
const format = require('util').format;
const importLazy = require('import-lazy')(require);
import UpdateNotifier from './update-notifier.js';

const configstore = importLazy('configstore');
const chalk = importLazy('chalk');
const semverDiff = importLazy('semver-diff');
const latestVersion = importLazy('latest-version');
const isNpm = importLazy('is-npm');
const boxen = importLazy('boxen');
const xdgBasedir = importLazy('xdg-basedir');
const ONE_DAY = 1000 * 60 * 60 * 24;

class UpdateNotifier {
constructor(options) {
options = options || {};
this.options = options;
options.pkg = options.pkg || {};

// Reduce pkg to the essential keys. with fallback to deprecated options
// TODO: Remove deprecated options at some point far into the future
options.pkg = {
name: options.pkg.name || options.packageName,
version: options.pkg.version || options.packageVersion
};

if (!options.pkg.name || !options.pkg.version) {
throw new Error('pkg.name and pkg.version required');
}

this.packageName = options.pkg.name;
this.packageVersion = options.pkg.version;
this.updateCheckInterval = typeof options.updateCheckInterval === 'number' ? options.updateCheckInterval : ONE_DAY;
this.hasCallback = typeof options.callback === 'function';
this.callback = options.callback || (() => {});
this.disabled = 'NO_UPDATE_NOTIFIER' in process.env ||
process.argv.indexOf('--no-update-notifier') !== -1;

if (!this.disabled && !this.hasCallback) {
try {
const ConfigStore = configstore();
this.config = new ConfigStore(`update-notifier-${this.packageName}`, {
optOut: false,
// Init with the current time so the first check is only
// after the set interval, so not to bother users right away
lastUpdateCheck: Date.now()
});
} catch (err) {
// Expecting error code EACCES or EPERM
const msg =
chalk().yellow(format(' %s update check failed ', options.pkg.name)) +
format('\n Try running with %s or get access ', chalk().cyan('sudo')) +
'\n to the local update config store via \n' +
chalk().cyan(format(' sudo chown -R $USER:$(id -gn $USER) %s ', xdgBasedir().config));

process.on('exit', () => {
console.error('\n' + boxen()(msg, {align: 'center'}));
});
}
}
}
check() {
if (this.hasCallback) {
this.checkNpm()
.then(update => this.callback(null, update))
.catch(err => this.callback(err));
return;
}

if (
!this.config ||
this.config.get('optOut') ||
this.disabled
) {
return;
}

this.update = this.config.get('update');

if (this.update) {
this.config.delete('update');
}

// Only check for updates on a set interval
if (Date.now() - this.config.get('lastUpdateCheck') < this.updateCheckInterval) {
return;
}

// Spawn a detached process, passing the options as an environment property
spawn(process.execPath, [path.join(__dirname, 'check.js'), JSON.stringify(this.options)], {
detached: true,
stdio: 'ignore'
}).unref();
}
checkNpm() {
return latestVersion()(this.packageName).then(latestVersion => {
return {
latest: latestVersion,
current: this.packageVersion,
type: semverDiff()(this.packageVersion, latestVersion) || 'latest',
name: this.packageName
};
});
}
notify(opts) {
if (!process.stdout.isTTY || isNpm() || !this.update) {
return this;
}

opts = Object.assign({isGlobal: true}, opts);

opts.message = opts.message || 'Update available ' + chalk().dim(this.update.current) + chalk().reset(' → ') +
chalk().green(this.update.latest) + ' \nRun ' + chalk().cyan('npm i ' + (opts.isGlobal ? '-g ' : '') + this.packageName) + ' to update';

opts.boxenOpts = opts.boxenOpts || {
padding: 1,
margin: 1,
align: 'center',
borderColor: 'yellow',
borderStyle: 'round'
};

const message = '\n' + boxen()(opts.message, opts.boxenOpts);

if (opts.defer === false) {
console.error(message);
} else {
process.on('exit', () => {
console.error(message);
});

process.on('SIGINT', () => {
console.error('');
process.exit();
});
}

return this;
}
}

module.exports = options => {
export default function updateNotifier(options) {
const updateNotifier = new UpdateNotifier(options);
updateNotifier.check();
return updateNotifier;
};

module.exports.UpdateNotifier = UpdateNotifier;
}
9 changes: 9 additions & 0 deletions license
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MIT License

Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
115 changes: 65 additions & 50 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,52 +1,67 @@
{
"name": "update-notifier",
"version": "2.2.0",
"description": "Update notifications for your CLI app",
"license": "BSD-2-Clause",
"repository": "yeoman/update-notifier",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=4"
},
"scripts": {
"test": "xo && mocha --timeout 20000"
},
"files": [
"index.js",
"check.js"
],
"keywords": [
"npm",
"update",
"updater",
"notify",
"notifier",
"check",
"checker",
"cli",
"module",
"package",
"version"
],
"dependencies": {
"boxen": "^1.0.0",
"chalk": "^1.0.0",
"configstore": "^3.0.0",
"import-lazy": "^2.1.0",
"is-npm": "^1.0.0",
"latest-version": "^3.0.0",
"semver-diff": "^2.0.0",
"xdg-basedir": "^3.0.0"
},
"devDependencies": {
"clear-module": "^2.1.0",
"fixture-stdout": "^0.2.1",
"mocha": "*",
"strip-ansi": "^3.0.1",
"xo": "^0.18.2"
}
"name": "update-notifier",
"version": "6.0.0",
"description": "Update notifications for your CLI app",
"license": "BSD-2-Clause",
"repository": "yeoman/update-notifier",
"funding": "https://github.com/yeoman/update-notifier?sponsor=1",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=14.16"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js",
"update-notifier.js",
"check.js"
],
"keywords": [
"npm",
"update",
"updater",
"notify",
"notifier",
"check",
"checker",
"cli",
"module",
"package",
"version"
],
"dependencies": {
"boxen": "^7.0.0",
"chalk": "^5.0.1",
"configstore": "^6.0.0",
"has-yarn": "^3.0.0",
"import-lazy": "^4.0.0",
"is-ci": "^3.0.1",
"is-installed-globally": "^0.4.0",
"is-npm": "^6.0.0",
"is-yarn-global": "^0.4.0",
"latest-version": "^6.0.0",
"pupa": "^3.1.0",
"semver": "^7.3.7",
"semver-diff": "^4.0.0",
"xdg-basedir": "^5.1.0"
},
"devDependencies": {
"ava": "^4.3.0",
"clear-module": "^4.1.2",
"fixture-stdout": "^0.2.1",
"mock-require": "^3.0.3",
"strip-ansi": "^7.0.1",
"xo": "^0.50.0"
},
"ava": {
"timeout": "20s",
"serial": true
}
}
Loading