Skip to content

Commit d9e40f9

Browse files
author
Pelle Wessman
authored
Add update-notifier (#9)
Alternative to #8 with a module that pulls in more dependencies, but which also have more features and eg. defers printing the result until the script quits, disables itself on CI, always prints to stderr etc Has quite a few more users as well. A good first step to try this out probably.
1 parent 71ec315 commit d9e40f9

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

cli.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ import * as cliCommands from './lib/commands/index.js'
88
import { logSymbols } from './lib/utils/chalk-markdown.js'
99
import { AuthError, InputError } from './lib/utils/errors.js'
1010
import { meowWithSubcommands } from './lib/utils/meow-with-subcommands.js'
11+
import { initUpdateNotifier } from './lib/utils/update-notifier.js'
1112

1213
// TODO: Add autocompletion using https://www.npmjs.com/package/omelette
1314

15+
initUpdateNotifier()
16+
1417
try {
1518
await meowWithSubcommands(
1619
cliCommands,

lib/utils/update-notifier.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { readFile } from 'node:fs/promises'
2+
3+
import updateNotifier from 'update-notifier'
4+
5+
/** @returns {void} */
6+
export function initUpdateNotifier () {
7+
readFile(new URL('../../package.json', import.meta.url), 'utf8')
8+
.then(rawPkg => {
9+
const pkg = JSON.parse(rawPkg)
10+
updateNotifier({ pkg }).notify()
11+
})
12+
.catch(() => {
13+
// Fail silently if package.json could not be read or parsed
14+
})
15+
}

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"@types/mocha": "^10.0.0",
4646
"@types/node": "^14.18.31",
4747
"@types/prompts": "^2.4.1",
48+
"@types/update-notifier": "^6.0.1",
4849
"@typescript-eslint/eslint-plugin": "^5.44.0",
4950
"@typescript-eslint/parser": "^5.44.0",
5051
"c8": "^7.12.0",
@@ -77,6 +78,7 @@
7778
"ora": "^6.1.2",
7879
"pony-cause": "^2.1.8",
7980
"prompts": "^2.4.2",
80-
"terminal-link": "^3.0.0"
81+
"terminal-link": "^3.0.0",
82+
"update-notifier": "^6.0.2"
8183
}
8284
}

0 commit comments

Comments
 (0)