summaryrefslogtreecommitdiffstats
path: root/lib/plugins/plugin.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/plugins/plugin.js')
-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;