From 7ea080b9d1b9d64eac676dd9ddb0be8f3e96c43f Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Sat, 13 Oct 2018 00:25:42 +0800 Subject: [PATCH] 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`. --- packages/@vue/cli-service/lib/Service.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/@vue/cli-service/lib/Service.js b/packages/@vue/cli-service/lib/Service.js index 1267045e1..668a65d63 100644 --- a/packages/@vue/cli-service/lib/Service.js +++ b/packages/@vue/cli-service/lib/Service.js @@ -159,7 +159,23 @@ module.exports = class Service { const projectPlugins = Object.keys(this.pkg.devDependencies || {}) .concat(Object.keys(this.pkg.dependencies || {})) .filter(isPlugin) - .map(idToPlugin) + .map(id => { + if ( + this.pkg.optionalDependencies && + id in this.pkg.optionalDependencies + ) { + let apply = () => {} + try { + apply = require(id) + } catch (e) { + warn(`Optional dependency ${id} is not installed.`) + } + + return { id, apply } + } else { + return idToPlugin(id) + } + }) plugins = builtInPlugins.concat(projectPlugins) }