Skip to content

Commit

Permalink
feat: add SKIP_UPDATE_CHECK env var (#358)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Oct 13, 2023
1 parent b1935ce commit 1b815a8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ warns if there is a newer version of CLI released

<!-- toc -->

- [@oclif/plugin-warn-if-update-available](#oclifplugin-warn-if-update-available)
- [What is this?](#what-is-this)
- [How it works](#how-it-works)
- [Installation](#installation)
- [Configuration](#configuration)
- [Example configuration](#example-configuration)
- [Environment Variables](#environment-variables)
<!-- tocstop -->

# What is this?
Expand Down Expand Up @@ -64,3 +67,8 @@ any of the following configuration properties:
}
}
```

# Environment Variables

`<CLI>_SKIP_UPDATE_CHECK`: Skip this version check
`<CLI>_FORCE_VERSION_CACHE_UPDATE`: Force the version cache to update
3 changes: 2 additions & 1 deletion src/hooks/init/check-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const hook: Hook<'init'> = async function ({config}) {
const checkVersion = async () => {
try {
// do not show warning if updating
if (process.argv[2] === 'update') return
if (process.argv[2] === 'update' || this.config.scopedEnvVarTrue('SKIP_UPDATE_CHECK')) return
const distTags = JSON.parse(await readFile(file, 'utf8'))
if (config.version.includes('-')) {
// to-do: handle prerelease channels
Expand All @@ -48,6 +48,7 @@ const hook: Hook<'init'> = async function ({config}) {

const refreshNeeded = async () => {
if (this.config.scopedEnvVarTrue('FORCE_VERSION_CACHE_UPDATE')) return true
if (this.config.scopedEnvVarTrue('SKIP_UPDATE_CHECK')) return false
try {
const {mtime} = await stat(file)
const staleAt = new Date(mtime.valueOf() + 1000 * 60 * 60 * 24 * timeoutInDays)
Expand Down

0 comments on commit 1b815a8

Please sign in to comment.