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 <[email protected]>
  • Loading branch information
wzrdtales committed Jun 8, 2019
1 parent f27dce0 commit 006ef5e
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 006ef5e

Please sign in to comment.