From 006ef5e273ff03efe38f93ff34fb7df017f9d801 Mon Sep 17 00:00:00 2001 From: Tobias Gurtzick Date: Sat, 8 Jun 2019 14:53:46 +0200 Subject: [PATCH] fix(plugin): handle non existent dependencies and improve UX fixes #628 Signed-off-by: Tobias Gurtzick --- index.js | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 1a33a5b3..0340e613 100644 --- a/index.js +++ b/index.js @@ -9,15 +9,26 @@ function loadPluginList (options) { try { fs.accessSync(path.join(options.cwd, 'package.json'), fs.constants.R_OK); } catch (err) { - return {}; + throw new Error( + 'There was no package.json found in the current working dir!', + options.cwd + ); + } + + try { + var plugins = JSON.parse( + fs.readFileSync(path.join(options.cwd, 'package.json'), 'utf-8') + ); + } catch (err) { + throw new Error('Error parsing package.json', err); } - var plugins = JSON.parse( - fs.readFileSync(path.join(options.cwd, 'package.json'), 'utf-8') - ); var targets = []; - plugins = Object.assign(plugins.dependencies, plugins.devDependencies); + plugins = Object.assign( + plugins.dependencies || {}, + plugins.devDependencies || {} + ); for (var plugin in plugins) { if (plugin.startsWith('db-migrate-plugin')) targets.push(plugin); @@ -65,7 +76,8 @@ module.exports.getInstance = function ( try { if (!options || !options.noPlugins) plugins = loadPlugins(options); } catch (ex) { - log.warn(ex); + log.verbose('No plugin could be loaded!'); + log.verbose(ex); } if (options && options.plugins) {