Skip to content

Commit 3a88152

Browse files
author
Guillaume Chau
committed
refactor(ui): update all plugins in one command which is much quicker
1 parent 80a847f commit 3a88152

File tree

4 files changed

+48
-30
lines changed

4 files changed

+48
-30
lines changed

packages/@vue/cli-ui/locales/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@
154154
"plugin-install": "Installing {arg0}...",
155155
"plugin-uninstall": "Uninstalling {arg0}...",
156156
"plugin-invoke": "Invoking {arg0}...",
157-
"plugin-update": "Updating {arg0}..."
157+
"plugin-update": "Updating {arg0}...",
158+
"plugins-update": "Updating {arg0} plugins..."
158159
}
159160
},
160161
"types": {

packages/@vue/cli-ui/src/graphql-api/connectors/plugins.js

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function findPlugins (deps) {
7676
)
7777
}
7878

79-
function list (file, context) {
79+
function list (file, context, resetApi = true) {
8080
const pkg = folders.readPackage(file, context)
8181
plugins = []
8282
plugins = plugins.concat(findPlugins(pkg.devDependencies || {}))
@@ -90,7 +90,7 @@ function list (file, context) {
9090
plugins.unshift(service)
9191
}
9292

93-
resetPluginApi(context)
93+
if (resetApi) resetPluginApi(context)
9494
return plugins
9595
}
9696

@@ -379,7 +379,7 @@ async function initPrompts (id, context) {
379379
await prompts.start()
380380
}
381381

382-
function update (id, context, multi = false) {
382+
function update (id, context) {
383383
return progress.wrap('plugin-update', context, async setProgress => {
384384
setProgress({
385385
status: 'plugin-update',
@@ -396,38 +396,56 @@ function update (id, context, multi = false) {
396396
type: 'info'
397397
}, context)
398398

399-
if (!multi) {
400-
notify({
401-
title: `Plugin updated`,
402-
message: `Plugin ${id} was successfully updated`,
403-
icon: 'done'
404-
})
405-
resetPluginApi(context)
406-
}
399+
notify({
400+
title: `Plugin updated`,
401+
message: `Plugin ${id} was successfully updated`,
402+
icon: 'done'
403+
})
404+
resetPluginApi(context)
407405

408406
currentPluginId = null
409407
return findOne(id)
410408
})
411409
}
412410

413411
async function updateAll (context) {
414-
const plugins = await list(cwd.get(), context)
415-
let updatedPlugins = []
416-
for (const plugin of plugins) {
417-
const version = await getVersion(plugin, context)
418-
if (version.current !== version.wanted) {
419-
updatedPlugins.push(await update(plugin.id, context, true))
412+
return progress.wrap('plugins-update', context, async setProgress => {
413+
const plugins = await list(cwd.get(), context, false)
414+
let updatedPlugins = []
415+
for (const plugin of plugins) {
416+
const version = await getVersion(plugin, context)
417+
if (version.current !== version.wanted) {
418+
updatedPlugins.push(plugin)
419+
}
420420
}
421-
}
422421

423-
notify({
424-
title: `Plugins updated`,
425-
message: `${updatedPlugins.length} plugin(s) were successfully updated`,
426-
icon: 'done'
427-
})
428-
resetPluginApi(context)
422+
if (!updatedPlugins.length) {
423+
notify({
424+
title: `No updates available`,
425+
message: `No plugin to update in the version ranges declared in package.json`,
426+
icon: 'done'
427+
})
428+
return []
429+
}
430+
431+
setProgress({
432+
status: 'plugins-update',
433+
args: [updatedPlugins.length]
434+
})
435+
436+
await updatePackage(cwd.get(), getCommand(), null, updatedPlugins.map(
437+
p => p.id
438+
).join(' '))
429439

430-
return updatedPlugins
440+
notify({
441+
title: `Plugins updated`,
442+
message: `${updatedPlugins.length} plugin(s) were successfully updated`,
443+
icon: 'done'
444+
})
445+
resetPluginApi(context)
446+
447+
return updatedPlugins
448+
})
431449
}
432450

433451
function getApi () {

packages/@vue/cli-ui/src/views/ProjectPlugins.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,8 @@
5050
</ApolloQuery>
5151
</ContentView>
5252

53-
<ProgressScreen
54-
progress-id="plugin-update"
55-
/>
53+
<ProgressScreen progress-id="plugin-update"/>
54+
<ProgressScreen progress-id="plugins-update"/>
5655
</div>
5756
</template>
5857

packages/@vue/cli/lib/util/installDeps.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ exports.updatePackage = async function (targetDir, command, cliRegistry, package
242242

243243
await addRegistryToArgs(command, args, cliRegistry)
244244

245-
args.push(packageName)
245+
packageName.split(' ').forEach(name => args.push(name))
246246

247247
debug(`command: `, command)
248248
debug(`args: `, args)

0 commit comments

Comments
 (0)