Skip to content

Commit

Permalink
Require Node.js 18
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Oct 27, 2023
1 parent a1d8d9d commit 431dac4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 40 deletions.
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=14.16"
"node": ">=18"
},
"scripts": {
"test": "xo && NODE_OPTIONS='--loader=esmock --no-warnings' ava"
Expand All @@ -37,26 +37,26 @@
"version"
],
"dependencies": {
"boxen": "^7.0.0",
"chalk": "^5.0.1",
"boxen": "^7.1.1",
"chalk": "^5.3.0",
"configstore": "^6.0.0",
"import-lazy": "^4.0.0",
"is-ci": "^3.0.1",
"is-in-ci": "^0.1.0",
"is-installed-globally": "^0.4.0",
"is-npm": "^6.0.0",
"latest-version": "^7.0.0",
"pupa": "^3.1.0",
"semver": "^7.3.7",
"semver": "^7.5.4",
"semver-diff": "^4.0.0",
"xdg-basedir": "^5.1.0"
},
"devDependencies": {
"ava": "^4.3.0",
"ava": "^5.3.1",
"clear-module": "^4.1.2",
"esmock": "^2.5.8",
"fixture-stdout": "^0.2.1",
"esmock": "^1.7.8",
"strip-ansi": "^7.0.1",
"xo": "^0.50.0"
"strip-ansi": "^7.1.0",
"xo": "^0.56.0"
},
"ava": {
"timeout": "20s",
Expand Down
24 changes: 6 additions & 18 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ Check update information.

Returns an `object` with:

- `latest` _(String)_ - Latest version.
- `current` _(String)_ - Current version.
- `type` _(String)_ - Type of current update. Possible values: `latest`, `major`, `minor`, `patch`, `prerelease`, `build`.
- `name` _(String)_ - Package name.
- `latest` *(string)* - Latest version.
- `current` *(string)* - Current version.
- `type` *(string)* - Type of current update. Possible values: `latest`, `major`, `minor`, `patch`, `prerelease`, `build`.
- `name` *(string)* - Package name.

### notifier.notify(options?)

Expand Down Expand Up @@ -191,8 +191,8 @@ Users of your module have the ability to opt-out of the update notifier by chang
Users can also opt-out by [setting the environment variable](https://github.com/sindresorhus/guides/blob/main/set-environment-variables.md) `NO_UPDATE_NOTIFIER` with any value or by using the `--no-update-notifier` flag on a per run basis.

The check is also skipped automatically:
- on CI
- in unit tests (when the `NODE_ENV` environment variable is `test`)
- [in CI](https://github.com/sindresorhus/is-in-ci)
- in unit tests (when the `NODE_ENV` environment variable is `test`)

## About

Expand All @@ -209,15 +209,3 @@ There are a bunch projects using it:
- [Node GH](https://github.com/node-gh/gh) - GitHub command line tool

[And 2700+ more…](https://www.npmjs.org/browse/depended/update-notifier)

---

<div align="center">
<b>
<a href="https://tidelift.com/subscription/pkg/npm-update_notifier?utm_source=npm-update-notifier&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
</b>
<br>
<sub>
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
</sub>
</div>
10 changes: 5 additions & 5 deletions test/update-notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,30 @@ test.afterEach(() => {
});

test('fetch info', async t => {
const updateNotifier = await esmock('../index.js', undefined, {'is-ci': false});
const updateNotifier = await esmock('../index.js', undefined, {'is-in-ci': false});
configstorePath = updateNotifier(generateSettings()).config.path;
const update = await updateNotifier(generateSettings()).fetchInfo();
console.log(update);
t.is(update.latest, '0.0.2');
});

test('fetch info with dist-tag', async t => {
const updateNotifier = await esmock('../index.js', undefined, {'is-ci': false});
const updateNotifier = await esmock('../index.js', undefined, {'is-in-ci': false});
configstorePath = updateNotifier(generateSettings()).config.path;
const update = await updateNotifier(generateSettings({distTag: '0.0.3-rc1'})).fetchInfo();
t.is(update.latest, '0.0.3-rc1');
});

test('don\'t initialize configStore when NO_UPDATE_NOTIFIER is set', async t => {
const updateNotifier = await esmock('../index.js', undefined, {'is-ci': false});
const updateNotifier = await esmock('../index.js', undefined, {'is-in-ci': false});
configstorePath = updateNotifier(generateSettings()).config.path;
process.env.NO_UPDATE_NOTIFIER = '1';
const notifier = updateNotifier(generateSettings());
t.is(notifier.config, undefined);
});

test('don\'t initialize configStore when --no-update-notifier is set', async t => {
const updateNotifier = await esmock('../index.js', undefined, {'is-ci': false});
const updateNotifier = await esmock('../index.js', undefined, {'is-in-ci': false});
configstorePath = updateNotifier(generateSettings()).config.path;
process.argv.push('--no-update-notifier');
const notifier = updateNotifier(generateSettings());
Expand All @@ -62,7 +62,7 @@ test('don\'t initialize configStore when --no-update-notifier is set', async t =

test('don\'t initialize configStore when NODE_ENV === "test"', async t => {
process.env.NODE_ENV = 'test';
const updateNotifier = await esmock('../index.js', undefined, {'is-ci': false});
const updateNotifier = await esmock('../index.js', undefined, {'is-in-ci': false});
const notifier = updateNotifier(generateSettings());
t.is(notifier.config, undefined);
});
16 changes: 8 additions & 8 deletions update-notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {isNpmOrYarn} from 'is-npm';
import isInstalledGlobally from 'is-installed-globally';
import boxen from 'boxen';
import {xdgConfig} from 'xdg-basedir';
import isCi from 'is-ci';
import isInCi from 'is-in-ci';
import pupa from 'pupa';

const __dirname = path.dirname(fileURLToPath(import.meta.url));
Expand All @@ -35,14 +35,14 @@ export default class UpdateNotifier {

constructor(options = {}) {
this.#options = options;
options.pkg = options.pkg || {};
options.distTag = options.distTag || 'latest';
options.pkg = options.pkg ?? {};
options.distTag = options.distTag ?? 'latest';

// 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,
name: options.pkg.name ?? options.packageName,
version: options.pkg.version ?? options.packageVersion,
};

if (!options.pkg.name || !options.pkg.version) {
Expand All @@ -55,7 +55,7 @@ export default class UpdateNotifier {
this.#isDisabled = 'NO_UPDATE_NOTIFIER' in process.env
|| process.env.NODE_ENV === 'test'
|| process.argv.includes('--no-update-notifier')
|| isCi;
|| isInCi;
this._shouldNotifyInNpmScript = options.shouldNotifyInNpmScript;

if (!this.#isDisabled) {
Expand Down Expand Up @@ -119,7 +119,7 @@ export default class UpdateNotifier {
return {
latest,
current: this.#packageVersion,
type: semverDiff(this.#packageVersion, latest) || distTag,
type: semverDiff(this.#packageVersion, latest) ?? distTag,
name: this._packageName,
};
}
Expand All @@ -145,7 +145,7 @@ export default class UpdateNotifier {

const template = options.message || defaultTemplate;

options.boxenOptions = options.boxenOptions || {
options.boxenOptions ??= {
padding: 1,
margin: 1,
textAlignment: 'center',
Expand Down

0 comments on commit 431dac4

Please sign in to comment.