Skip to content

Commit 7ea080b

Browse files
committed
fix: should not throw when a plugin listed in optionalDependencies is not installed
This bug is due to `normalize-package-data` (required by `read-pkg`) adding `optionalDependencies` to `dependencies`.
1 parent c6ab80f commit 7ea080b

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,23 @@ module.exports = class Service {
159159
const projectPlugins = Object.keys(this.pkg.devDependencies || {})
160160
.concat(Object.keys(this.pkg.dependencies || {}))
161161
.filter(isPlugin)
162-
.map(idToPlugin)
162+
.map(id => {
163+
if (
164+
this.pkg.optionalDependencies &&
165+
id in this.pkg.optionalDependencies
166+
) {
167+
let apply = () => {}
168+
try {
169+
apply = require(id)
170+
} catch (e) {
171+
warn(`Optional dependency ${id} is not installed.`)
172+
}
173+
174+
return { id, apply }
175+
} else {
176+
return idToPlugin(id)
177+
}
178+
})
163179
plugins = builtInPlugins.concat(projectPlugins)
164180
}
165181

0 commit comments

Comments
 (0)