Skip to content

feat: add --next flag to vue upgrade to check for beta versions #4404

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/@vue/cli/bin/vue.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,12 @@ program
})

program
.command('upgrade [package-name]')
.command('upgrade [plugin-name]')
.description('(experimental) upgrade vue cli service / plugins')
.option('-t, --to <version>', 'upgrade <package-name> to a version that is not latest')
.option('-r, --registry <url>', 'Use specified npm registry when installing dependencies')
.option('--all', 'Upgrade all plugins')
.option('--next', 'Also check for alpha / beta / rc versions when upgrading')
.action((packageName, cmd) => {
require('../lib/upgrade')(packageName, cleanArgs(cmd))
})
Expand Down
25 changes: 17 additions & 8 deletions packages/@vue/cli/lib/Upgrader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const fs = require('fs')
const path = require('path')
const chalk = require('chalk')
const execa = require('execa')
const semver = require('semver')
const {
log,
done,
Expand Down Expand Up @@ -32,11 +33,11 @@ module.exports = class Upgrader {
this.pm = new PackageManager({ context })
}

async upgradeAll () {
async upgradeAll (includeNext) {
// TODO: should confirm for major version upgrades
// for patch & minor versions, upgrade directly
// for major versions, prompt before upgrading
const upgradable = await this.getUpgradable()
const upgradable = await this.getUpgradable(includeNext)

if (!upgradable.length) {
done('Seems all plugins are up to date. Good work!')
Expand Down Expand Up @@ -75,6 +76,10 @@ module.exports = class Upgrader {
}

targetVersion = await this.pm.getRemoteVersion(packageName, targetVersion)
if (!options.to && options.next) {
const next = await this.pm.getRemoteVersion(packageName, 'next')
targetVersion = semver.gte(targetVersion, next) ? targetVersion : next
}
stopSpinner()
}

Expand Down Expand Up @@ -177,7 +182,7 @@ module.exports = class Upgrader {
migrator.printExitLogs()
}

async getUpgradable () {
async getUpgradable (includeNext) {
const upgradable = []

// get current deps
Expand All @@ -191,9 +196,13 @@ module.exports = class Upgrader {
const installed = await this.pm.getInstalledVersion(name)
const wanted = await this.pm.getRemoteVersion(name, range)

const latest = await this.pm.getRemoteVersion(name)
let latest = await this.pm.getRemoteVersion(name)
if (includeNext) {
const next = await this.pm.getRemoteVersion(name, 'next')
latest = semver.gte(latest, next) ? latest : next
}

if (installed !== latest) {
if (semver.lt(installed, latest)) {
// always list @vue/cli-service as the first one
// as it's depended by all other plugins
if (name === '@vue/cli-service') {
Expand All @@ -208,9 +217,9 @@ module.exports = class Upgrader {
return upgradable
}

async checkForUpdates () {
async checkForUpdates (includeNext) {
logWithSpinner('Gathering package information...')
const upgradable = await this.getUpgradable()
const upgradable = await this.getUpgradable(includeNext)
stopSpinner()

if (!upgradable.length) {
Expand All @@ -225,7 +234,7 @@ module.exports = class Upgrader {
if (!Number.isFinite(namePad)) {
namePad = 30
}
const pads = [namePad, 12, 12, 12, 0]
const pads = [namePad, 16, 16, 16, 0]
console.log(
' ' +
['Name', 'Installed', 'Wanted', 'Latest', 'Command to upgrade'].map(
Expand Down
4 changes: 2 additions & 2 deletions packages/@vue/cli/lib/upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ async function upgrade (packageName, options, context = process.cwd()) {
}

if (options.all) {
return upgrader.upgradeAll()
return upgrader.upgradeAll(options.next)
}

return upgrader.checkForUpdates()
return upgrader.checkForUpdates(options.next)
}

return upgrader.upgrade(packageName, options)
Expand Down