Skip to content

Commit

Permalink
fix: always pull new version when current changes
Browse files Browse the repository at this point in the history
also ignore when not on stable channel
  • Loading branch information
jdx committed Apr 20, 2018
1 parent 1c8fe11 commit f4e5f93
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/get_version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ async function touch(file: string) {
}
}

async function run(name: string, file: string) {
async function run(name: string, file: string, version: string) {
await touch(file)
const {body} = await HTTP.get(`https://registry.npmjs.org/${name.replace('/', '%2f')}`, {timeout: 5000})
await fs.outputJSON(file, body['dist-tags'])
await fs.outputJSON(file, {...body['dist-tags'], current: version})
process.exit(0)
}

run(process.argv[2], process.argv[3])
run(process.argv[2], process.argv[3], process.argv[4])
.catch(require('@oclif/errors/handle'))
12 changes: 9 additions & 3 deletions src/hooks/init/check_update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ const hook: Hook<'init'> = async function ({config}) {
const checkVersion = async () => {
try {
const distTags = await fs.readJSON(file)
if (config.version.includes('-')) {
// TODO: handle channels
return
}
if (distTags && distTags.latest && semver.gt(distTags.latest.split('-')[0], config.version.split('-')[0])) {
const chalk: typeof Chalk = require('chalk')
this.warn(`${config.name} update available from ${chalk.greenBright(config.version)} to ${chalk.greenBright(distTags.latest)}`)
Expand All @@ -25,10 +29,12 @@ 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 timeoutInDays = cfg.timeoutInDays || 60
const {mtime} = await fs.stat(file)
const staleAt = new Date(mtime.valueOf() + 1000 * 60 * 60 * 24 * timeoutInDays)
return staleAt < new Date()
if (staleAt < new Date()) return true
const versions = await fs.readJSON(file)
return !versions.current || versions.current !== config.version
} catch (err) {
debug(err)
return true
Expand All @@ -39,7 +45,7 @@ const hook: Hook<'init'> = async function ({config}) {
debug('spawning version refresh')
spawn(
process.execPath,
[path.join(__dirname, '../../../lib/get_version'), config.name, file],
[path.join(__dirname, '../../../lib/get_version'), config.name, file, config.version],
{
detached: !config.windows,
stdio: 'ignore',
Expand Down

0 comments on commit f4e5f93

Please sign in to comment.