From 7c1bdbf26fdb755d0984f9852e73b5a76798e168 Mon Sep 17 00:00:00 2001 From: Jeff Dickey <216188+jdxcode@users.noreply.github.com> Date: Sat, 7 Apr 2018 18:45:53 -0700 Subject: [PATCH] feat: increase timeout to weekly and add timeoutInDays configuration --- README.md | 6 +++++- src/hooks/init/check_update.ts | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d869fc27..2bc87cb0 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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. diff --git a/src/hooks/init/check_update.ts b/src/hooks/init/check_update.ts index 9e62e8c4..1a53baef 100644 --- a/src/hooks/init/check_update.ts +++ b/src/hooks/init/check_update.ts @@ -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)