Skip to content

Commit 91b9da9

Browse files
committed
fix(plugin): handle non existent dependencies and improve UX
fixes #628 Signed-off-by: Tobias Gurtzick <magic@wizardtales.com>
1 parent 9334ee2 commit 91b9da9

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

index.js

+21-8
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,26 @@ function loadPluginList (options) {
99
try {
1010
fs.accessSync(path.join(options.cwd, 'package.json'), fs.constants.R_OK);
1111
} catch (err) {
12-
return {};
12+
throw new Error(
13+
'There was no package.json found in the current working dir!',
14+
options.cwd
15+
);
1316
}
14-
var plugins = JSON.parse(
15-
fs.readFileSync(path.join(options.cwd, 'package.json'), 'utf-8')
16-
);
17+
18+
try {
19+
var plugins = JSON.parse(
20+
fs.readFileSync(path.join(options.cwd, 'package.json'), 'utf-8')
21+
);
22+
} catch (err) {
23+
throw new Error('Error parsing package.json', err);
24+
}
25+
1726
var targets = [];
1827

19-
plugins = Object.assign(plugins.dependencies, plugins.devDependencies);
28+
plugins = Object.assign(
29+
plugins.dependencies || {},
30+
plugins.devDependencies || {}
31+
);
2032

2133
for (var plugin in plugins) {
2234
if (plugin.startsWith('db-migrate-plugin')) targets.push(plugin);
@@ -62,12 +74,13 @@ module.exports.getInstance = function (
6274
var plugins = {};
6375

6476
try {
65-
if (!options.noPlugins) plugins = loadPlugins(options);
77+
if (!options || !options.noPlugins) plugins = loadPlugins(options);
6678
} catch (ex) {
67-
log.warn(ex);
79+
log.verbose('No plugin could be loaded!');
80+
log.verbose(ex);
6881
}
6982

70-
if (options.plugins) {
83+
if (options && options.plugins) {
7184
plugins = Object.assign(plugins, options.plugins);
7285
}
7386

0 commit comments

Comments
 (0)