Skip to content

Commit

Permalink
feat: increase timeout to weekly and add timeoutInDays configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Apr 8, 2018
1 parent c973623 commit 7c1bdbf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ This plugin shows a warning message if a user is running an out of date CLI.

# How it works

This checks the version against the npm registry asynchronously in a forked process, at most once per 24 hours. It then saves a version file to the cache directory that will enable the warning. The upside of this method is that it won't block a user while they're using your CLI—the downside is that it will only display _after_ running a command that fetches the new version.
This checks the version against the npm registry asynchronously in a forked process, at most once per 7 days. It then saves a version file to the cache directory that will enable the warning. The upside of this method is that it won't block a user while they're using your CLI—the downside is that it will only display _after_ running a command that fetches the new version.

# Installation

Expand All @@ -41,3 +41,7 @@ Add the plugin to your project with `yarn add @oclif/plugin-warn-if-update-avail
}
}
```

# Configuration

In `package.json`, set `oclif['warn-if-update-available'].timeoutInDays` to change the timeout duration between checks.
4 changes: 3 additions & 1 deletion src/hooks/init/check_update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ const hook: Hook<'init'> = async function ({config}) {

const refreshNeeded = async () => {
try {
const cfg = (config.pjson.oclif as any)['warn-if-update-available'] || {}
const timeoutInDays = cfg.timeoutInDays || 7
const {mtime} = await fs.stat(file)
const staleAt = new Date(mtime.valueOf() + 1000 * 60 * 60 * 24)
const staleAt = new Date(mtime.valueOf() + 1000 * 60 * 60 * 24 * timeoutInDays)
return staleAt < new Date()
} catch (err) {
debug(err)
Expand Down

0 comments on commit 7c1bdbf

Please sign in to comment.