Skip to content

fix(cli): fix module resolve of preset generator #5968

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

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions packages/@vue/cli/lib/Creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ module.exports = class Creator extends EventEmitter {

await clearConsole()
const pm = new PackageManager({ context, forcePackageManager: packageManager })
let presetPm = null

log(`✨ Creating project in ${chalk.yellow(context)}.`)
this.emit('creation', { event: 'creating' })
Expand All @@ -154,6 +155,10 @@ module.exports = class Creator extends EventEmitter {
const deps = Object.keys(preset.plugins)
deps.forEach(dep => {
if (preset.plugins[dep]._isPreset) {
const { _hasPackageJson, _dir } = preset.plugins[dep]
if (!_hasPackageJson) return
if (!path.relative(pm.context, _dir)) return
presetPm = new PackageManager({ context: _dir })
return
}

Expand Down Expand Up @@ -213,6 +218,7 @@ module.exports = class Creator extends EventEmitter {
// in development, avoid installation process
await require('./util/setupDevProject')(context)
} else {
presetPm && await presetPm.install()
await pm.install()
}

Expand Down
2 changes: 2 additions & 0 deletions packages/@vue/cli/lib/util/loadPresetFromDir.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ module.exports = async function loadPresetFromDir (dir) {
if (hasGenerator) {
(preset.plugins || (preset.plugins = {}))[dir.replace(/[\/]$/, '')] = {
_isPreset: true,
_dir: dir,
_hasPackageJson: fs.existsSync(path.join(dir, 'package.json')),
prompts: true
}
}
Expand Down