From 431dac46c693dad384db03bbb89734a56f21ea08 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sat, 28 Oct 2023 01:39:41 +0700 Subject: [PATCH] Require Node.js 18 --- package.json | 18 +++++++++--------- readme.md | 24 ++++++------------------ test/update-notifier.js | 10 +++++----- update-notifier.js | 16 ++++++++-------- 4 files changed, 28 insertions(+), 40 deletions(-) diff --git a/package.json b/package.json index 95a8d37..6967d14 100644 --- a/package.json +++ b/package.json @@ -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" @@ -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", diff --git a/readme.md b/readme.md index f5a97b5..9f02f32 100644 --- a/readme.md +++ b/readme.md @@ -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?) @@ -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 @@ -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) - ---- - -
- - Get professional support for this package with a Tidelift subscription - -
- - Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies. -
-
diff --git a/test/update-notifier.js b/test/update-notifier.js index f7e69af..8976f97 100644 --- a/test/update-notifier.js +++ b/test/update-notifier.js @@ -30,7 +30,7 @@ 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); @@ -38,14 +38,14 @@ test('fetch info', async t => { }); 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()); @@ -53,7 +53,7 @@ test('don\'t initialize configStore when NO_UPDATE_NOTIFIER is set', async t => }); 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()); @@ -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); }); diff --git a/update-notifier.js b/update-notifier.js index 7d6c141..0a9f539 100644 --- a/update-notifier.js +++ b/update-notifier.js @@ -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)); @@ -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) { @@ -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) { @@ -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, }; } @@ -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',