Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit 5220b63

Browse files
authored
Adding validation to only show upgrade message when checking for version (#1159)
1 parent 7efaf27 commit 5220b63

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

packages/cli/src/hooks/init/inithook.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ const hook: Hook<'init'> = async function (opts) {
5858
// if there's no timestamp in config, create one and check for updates
5959
// if there is a timestamp in config and it's not from today, check for updates
6060
const lastCheck = userConfig.lastVersionCheck ? new Date(userConfig.lastVersionCheck) : null
61-
if (!isToday(lastCheck, curDateTime)) {
61+
if ((opts.id === '-v'
62+
|| opts.id === '--version')
63+
&& !isToday(lastCheck, curDateTime)) {
6264
await checkForUpdate()
6365
await updateUserConfig(curDateTime)
6466
}

packages/cli/test/commands/inithook.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ describe('Update available to stdout', () => {
114114
.loadConfig({root: upgradeavailable})
115115
.stub(semver, 'gt', () => true)
116116
.stdout()
117-
.hook('init', {argv: ['arg']}, {root: upgradeavailable})
117+
.hook('init', {id: '-v', argv: ['arg']}, {root: upgradeavailable})
118118
.do(output => {
119119
expect(output.stdout).to.contain('Update available')
120120
})
@@ -132,7 +132,7 @@ describe('Update available to stdout', () => {
132132
.loadConfig({root: lastversioncheck})
133133
.stub(semver, 'gt', () => true)
134134
.stdout()
135-
.hook('init', {argv: ['arg']}, {root: lastversioncheck})
135+
.hook('init', {id: '-v', argv: ['arg']}, {root: lastversioncheck})
136136
.do(output => {
137137
expect(output.stdout).to.contain('Update available')
138138
})

0 commit comments

Comments
 (0)