summaryrefslogtreecommitdiffstats
path: root/lib/plugins
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-02-17 15:58:35 +0100
committerSamy Pessé <samypesse@gmail.com>2016-02-17 15:58:35 +0100
commit1db3f3deab86c69f31b1cf1454bb23315639025a (patch)
tree9ec9e5fbf8b719bec9d82fcad86d2bf7a0869767 /lib/plugins
parentb2af55ac63886cba2075043554ff78c787cbb9e1 (diff)
downloadgitbook-1db3f3deab86c69f31b1cf1454bb23315639025a.zip
gitbook-1db3f3deab86c69f31b1cf1454bb23315639025a.tar.gz
gitbook-1db3f3deab86c69f31b1cf1454bb23315639025a.tar.bz2
Don't fail if plugin is "empty"
Diffstat (limited to 'lib/plugins')
-rw-r--r--lib/plugins/plugin.js20
1 files changed, 16 insertions, 4 deletions
diff --git a/lib/plugins/plugin.js b/lib/plugins/plugin.js
index 64ae75f..0216a18 100644
--- a/lib/plugins/plugin.js
+++ b/lib/plugins/plugin.js
@@ -7,6 +7,12 @@ var error = require('../utils/error');
var gitbook = require('../gitbook');
var registry = require('./registry');
+// Return true if an error is a "module not found"
+function isModuleNotFound(err) {
+ return err.message.indexOf('Cannot find module') >= 0;
+}
+
+
function BookPlugin(book, pluginId) {
this.book = book;
this.log = this.book.log;
@@ -47,7 +53,7 @@ BookPlugin.prototype.load = function() {
that.packageInfos = require(res);
} catch (err) {
// Wait on https://github.com/substack/node-resolve/pull/81 to be merged
- if (err.message.indexOf('Cannot find module') < 0) throw err;
+ if (!isModuleNotFound(err)) throw err;
that.packageInfos = undefined;
that.content = undefined;
@@ -59,9 +65,15 @@ BookPlugin.prototype.load = function() {
try {
that.content = require(resolve.sync(that.npmId, { basedir: baseDir }));
} catch(err) {
- throw new error.PluginError(err, {
- plugin: that.id
- });
+ // It's no big deal if the plugin doesn't have an "index.js"
+ // (For example: themes)
+ if (isModuleNotFound(err)) {
+ that.content = {};
+ } else {
+ throw new error.PluginError(err, {
+ plugin: that.id
+ });
+ }
}
return true;