Skip to content

Commit

Permalink
fix(plugin): handle non existent dependencies and improve UX
Browse files Browse the repository at this point in the history
fixes #628

Signed-off-by: Tobias Gurtzick <magic@wizardtales.com>
  • Loading branch information
wzrdtales committed Jun 8, 2019
1 parent 9334ee2 commit 91b9da9
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +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
);
}
var plugins = JSON.parse(
fs.readFileSync(path.join(options.cwd, 'package.json'), 'utf-8')
);

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 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);
Expand Down Expand Up @@ -62,12 +74,13 @@ module.exports.getInstance = function (
var plugins = {};

try {
if (!options.noPlugins) plugins = loadPlugins(options);
if (!options || !options.noPlugins) plugins = loadPlugins(options);
} catch (ex) {
log.warn(ex);
log.verbose('No plugin could be loaded!');
log.verbose(ex);
}

if (options.plugins) {
if (options && options.plugins) {
plugins = Object.assign(plugins, options.plugins);
}

Expand Down

0 comments on commit 91b9da9

Please sign in to comment.