Skip to content

Commit 3479f21

Browse files
authored
refactor(plugin): invoke is now done in child process (#3778)
1 parent 5dfcc7e commit 3479f21

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

packages/@vue/cli-service/lib/PluginAPI.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,7 @@ class PluginAPI {
166166
} catch (e) {
167167
return fs.readFileSync(absolutePath, 'utf-8')
168168
}
169-
}
170-
else {
169+
} else {
171170
return fs.readFileSync(absolutePath, 'utf-8')
172171
}
173172
}

packages/@vue/cli-ui/apollo-server/connectors/plugins.js

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ const {
2727
getPluginLink,
2828
resolveModule,
2929
loadModule,
30-
clearModule
30+
clearModule,
31+
execa
3132
} = require('@vue/cli-shared-utils')
3233
const {
3334
progress: installProgress,
3435
installPackage,
3536
uninstallPackage,
3637
updatePackage
3738
} = require('@vue/cli/lib/util/installDeps')
38-
const invoke = require('@vue/cli/lib/invoke')
3939
const { getCommand } = require('../util/command')
4040
const ipc = require('../util/ipc')
4141
const { log } = require('../util/logger')
@@ -446,7 +446,32 @@ function runInvoke (id, context) {
446446
currentPluginId = id
447447
// Allow plugins that don't have a generator
448448
if (resolveModule(`${id}/generator`, cwd.get())) {
449-
await invoke(id, prompts.getAnswers(), cwd.get())
449+
const child = execa('vue', [
450+
'invoke',
451+
id,
452+
'--$inlineOptions',
453+
JSON.stringify(prompts.getAnswers())
454+
], {
455+
cwd: cwd.get(),
456+
stdio: ['inherit', 'pipe', 'inherit']
457+
})
458+
459+
const onData = buffer => {
460+
const text = buffer.toString().trim()
461+
if (text) {
462+
setProgress({
463+
info: text
464+
})
465+
logs.add({
466+
type: 'info',
467+
message: text
468+
}, context)
469+
}
470+
}
471+
472+
child.stdout.on('data', onData)
473+
474+
await child
450475
}
451476
// Run plugin api
452477
runPluginApi(id, getApi(cwd.get()), context)

packages/@vue/cli/lib/invoke.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,14 @@ async function invoke (pluginName, options = {}, context = process.cwd()) {
8484
// resolve options if no command line options (other than --registry) are passed,
8585
// and the plugin contains a prompt module.
8686
// eslint-disable-next-line prefer-const
87-
let { registry, ...pluginOptions } = options
88-
if (!Object.keys(pluginOptions).length) {
87+
let { registry, $inlineOptions, ...pluginOptions } = options
88+
if ($inlineOptions) {
89+
try {
90+
pluginOptions = JSON.parse($inlineOptions)
91+
} catch (e) {
92+
throw new Error(`Couldn't parse inline options JSON: ${e.message}`)
93+
}
94+
} else if (!Object.keys(pluginOptions).length) {
8995
let pluginPrompts = loadModule(`${id}/prompts`, context)
9096
if (pluginPrompts) {
9197
if (typeof pluginPrompts === 'function') {

0 commit comments

Comments
 (0)