Skip to content

Commit e759b2c

Browse files
author
Guillaume Chau
committed
fix(ui): mock install/uninstall in debug mode
1 parent 24d5e7b commit e759b2c

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,25 @@ function isPackage (file, context) {
4949
return fs.existsSync(path.join(file, 'package.json'))
5050
}
5151

52-
function readPackage (file, context) {
53-
const cachedValue = pkgCache.get(file)
54-
if (cachedValue) {
55-
return cachedValue
52+
function readPackage (file, context, force = false) {
53+
if (!force) {
54+
const cachedValue = pkgCache.get(file)
55+
if (cachedValue) {
56+
return cachedValue
57+
}
5658
}
5759
const pkg = fs.readJsonSync(path.join(file, 'package.json'))
5860
pkgCache.set(file, pkg)
5961
return pkg
6062
}
6163

64+
function writePackage ({ file, data }, context) {
65+
fs.outputJsonSync(path.join(file, 'package.json'), data, {
66+
spaces: 2
67+
})
68+
return true
69+
}
70+
6271
function isVueProject (file, context) {
6372
if (!isPackage(file)) return false
6473

@@ -93,6 +102,7 @@ module.exports = {
93102
openParent,
94103
isPackage,
95104
readPackage,
105+
writePackage,
96106
isVueProject,
97107
listFavorite,
98108
setFavorite,

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,11 @@ function install (id, context) {
247247
})
248248
currentPluginId = id
249249
installationStep = 'install'
250-
await installPackage(cwd.get(), getCommand(), null, id)
250+
if (process.env.VUE_CLI_DEBUG && isOfficialPlugin(id)) {
251+
mockInstall(id, context)
252+
} else {
253+
await installPackage(cwd.get(), getCommand(), null, id)
254+
}
251255
await initPrompts(id, context)
252256
installationStep = 'config'
253257

@@ -261,6 +265,13 @@ function install (id, context) {
261265
})
262266
}
263267

268+
function mockInstall (id, context) {
269+
const pkg = folders.readPackage(cwd.get(), context, true)
270+
pkg.devDependencies[id] = '*'
271+
folders.writePackage({ file: cwd.get(), data: pkg }, context)
272+
return true
273+
}
274+
264275
function uninstall (id, context) {
265276
return progress.wrap(PROGRESS_ID, context, async setProgress => {
266277
setProgress({
@@ -269,7 +280,11 @@ function uninstall (id, context) {
269280
})
270281
installationStep = 'uninstall'
271282
currentPluginId = id
272-
await uninstallPackage(cwd.get(), getCommand(), null, id)
283+
if (process.env.VUE_CLI_DEBUG && isOfficialPlugin(id)) {
284+
mockUninstall(id, context)
285+
} else {
286+
await uninstallPackage(cwd.get(), getCommand(), null, id)
287+
}
273288
currentPluginId = null
274289
installationStep = null
275290

@@ -283,6 +298,13 @@ function uninstall (id, context) {
283298
})
284299
}
285300

301+
function mockUninstall (id, context) {
302+
const pkg = folders.readPackage(cwd.get(), context, true)
303+
delete pkg.devDependencies[id]
304+
folders.writePackage({ file: cwd.get(), data: pkg }, context)
305+
return true
306+
}
307+
286308
function runInvoke (id, context) {
287309
return progress.wrap(PROGRESS_ID, context, async setProgress => {
288310
setProgress({

0 commit comments

Comments
 (0)