Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: oclif/plugin-warn-if-update-available
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 2.0.50
Choose a base ref
...
head repository: oclif/plugin-warn-if-update-available
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 2.1.0
Choose a head ref
  • 2 commits
  • 5 files changed
  • 3 contributors

Commits on Sep 5, 2023

  1. feat: dependency reduction and deferred/smaller imports (#413)

    * feat: dependency reduction and deferred/smaller imports
    
    * refactor: debug where it was
    
    ---------
    
    Co-authored-by: Mike Donnalley <mdonnalley@salesforce.com>
    mshanemc and mdonnalley authored Sep 5, 2023
    Copy the full SHA
    1676696 View commit details
  2. Copy the full SHA
    774f54c View commit details
Showing with 74 additions and 136 deletions.
  1. +9 −0 CHANGELOG.md
  2. +3 −5 package.json
  3. +5 −4 src/get-version.ts
  4. +13 −14 src/hooks/init/check-update.ts
  5. +44 −113 yarn.lock
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# [2.1.0](https://github.com/oclif/plugin-warn-if-update-available/compare/2.0.50...2.1.0) (2023-09-05)


### Features

* dependency reduction and deferred/smaller imports ([#413](https://github.com/oclif/plugin-warn-if-update-available/issues/413)) ([1676696](https://github.com/oclif/plugin-warn-if-update-available/commit/1676696eb577f5dc5ba2601e5da2ab986d3b3fc6))



## [2.0.50](https://github.com/oclif/plugin-warn-if-update-available/compare/2.0.49...2.0.50) (2023-09-03)


8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
{
"name": "@oclif/plugin-warn-if-update-available",
"description": "warns if there is a newer version of CLI released",
"version": "2.0.50",
"version": "2.1.0",
"author": "Salesforce",
"bugs": "https://github.com/oclif/plugin-warn-if-update-available/issues",
"dependencies": {
"@oclif/core": "^2.15.0",
"chalk": "^4.1.0",
"debug": "^4.1.0",
"fs-extra": "^9.0.1",
"http-call": "^5.2.2",
"lodash": "^4.17.21",
"lodash.template": "^4.5.0",
"semver": "^7.5.4"
},
"devDependencies": {
"@oclif/test": "^1.2.8",
"@types/chai": "^4.3.5",
"@types/fs-extra": "^9.0.1",
"@types/lodash": "^4.14.197",
"@types/lodash.template": "^4.5.1",
"@types/mocha": "^8.0.0",
"@types/node": "^14.18.58",
"@types/semver": "^7.5.1",
9 changes: 5 additions & 4 deletions src/get-version.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as fs from 'fs-extra'
import {writeFile, mkdir} from 'fs/promises'
import HTTP from 'http-call'
import {dirname} from 'path'

// eslint-disable-next-line max-params
async function run(name: string, file: string, version: string, registry: string, authorization: string) {
@@ -8,10 +9,10 @@ async function run(name: string, file: string, version: string, registry: string
name.replace('/', '%2f'), // scoped packages need escaped separator
].join('/')
const headers = authorization ? {authorization} : {}

await fs.outputJSON(file, {current: version, headers}) // touch file with current version to prevent multiple updates
await mkdir(dirname(file), {recursive: true})
await writeFile(file, JSON.stringify({current: version, headers})) // touch file with current version to prevent multiple updates
const {body} = await HTTP.get<any>(url, {headers, timeout: 5000})
await fs.outputJSON(file, {...body['dist-tags'], current: version, authorization})
await writeFile(file, JSON.stringify({...body['dist-tags'], current: version, authorization}))
process.exit(0) // eslint-disable-line unicorn/no-process-exit, no-process-exit
}

27 changes: 13 additions & 14 deletions src/hooks/init/check-update.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import {Hook} from '@oclif/core'
import * as Chalk from 'chalk'
import type {Chalk} from 'chalk'
import {spawn} from 'child_process'
import * as fs from 'fs-extra'
import * as _ from 'lodash'
import * as path from 'path'
import * as semver from 'semver'

const debug = require('debug')('update-check')
import {readFile, stat} from 'fs/promises'
import {join} from 'path'

const hook: Hook<'init'> = async function ({config}) {
const file = path.join(config.cacheDir, 'version')
const file = join(config.cacheDir, 'version')

// Destructure package.json configuration with defaults
const {
@@ -23,15 +19,16 @@ const hook: Hook<'init'> = async function ({config}) {
try {
// do not show warning if updating
if (process.argv[2] === 'update') return
const distTags = await fs.readJSON(file)
const distTags = JSON.parse(await readFile(file, 'utf8'))
if (config.version.includes('-')) {
// to-do: handle channels
return
}
if (distTags && distTags.latest && semver.gt(distTags.latest.split('-')[0], config.version.split('-')[0])) {
const chalk: typeof Chalk = require('chalk')
const template = _.template
const semverGt = await import('semver/functions/gt')
if (distTags && distTags.latest && semverGt(distTags.latest.split('-')[0], config.version.split('-')[0])) {
const chalk: Chalk = require('chalk')
// Default message if the user doesn't provide one
const template = require('lodash.template')
this.warn(template(message)({
chalk,
config,
@@ -46,20 +43,22 @@ const hook: Hook<'init'> = async function ({config}) {
const refreshNeeded = async () => {
if (this.config.scopedEnvVarTrue('FORCE_VERSION_CACHE_UPDATE')) return true
try {
const {mtime} = await fs.stat(file)
const {mtime} = await stat(file)
const staleAt = new Date(mtime.valueOf() + (1000 * 60 * 60 * 24 * timeoutInDays))
return staleAt < new Date()
} catch (error) {
const debug = require('debug')('update-check')
debug(error)
return true
}
}

const spawnRefresh = async () => {
const debug = require('debug')('update-check')
debug('spawning version refresh')
spawn(
process.execPath,
[path.join(__dirname, '../../../lib/get-version'), config.name, file, config.version, registry, authorization],
[join(__dirname, '../../../lib/get-version'), config.name, file, config.version, registry, authorization],
{
detached: !config.windows,
stdio: 'ignore',
Loading