diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-02-17 11:52:31 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-02-17 11:52:31 +0100 |
commit | 7c575e1b43d75a22bad035a3ce62110572dff1c9 (patch) | |
tree | 83b31c05128a470b646114fe2d7671c89e6c31d3 /lib/plugins/plugin.js | |
parent | c89c253f294df6820eeea6f50ec98dcd672ec8d3 (diff) | |
download | gitbook-7c575e1b43d75a22bad035a3ce62110572dff1c9.zip gitbook-7c575e1b43d75a22bad035a3ce62110572dff1c9.tar.gz gitbook-7c575e1b43d75a22bad035a3ce62110572dff1c9.tar.bz2 |
Fix loading of plugins
Diffstat (limited to 'lib/plugins/plugin.js')
-rw-r--r-- | lib/plugins/plugin.js | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/lib/plugins/plugin.js b/lib/plugins/plugin.js index 7ce29e4..4ed619c 100644 --- a/lib/plugins/plugin.js +++ b/lib/plugins/plugin.js @@ -1,3 +1,4 @@ +var _ = require('lodash'); var path = require('path'); var resolve = require('resolve'); @@ -15,6 +16,8 @@ function BookPlugin(book, pluginId) { this.packageInfos = undefined; this.content = undefined; + + _.bindAll(this); } // Return true if plugin has been loaded correctly @@ -31,18 +34,19 @@ BookPlugin.prototype.load = function() { } // Try loading plugins from different location - var promise = Promise.some([ + var p = Promise.some([ this.book.resolve('node_modules'), __dirname ], function(baseDir) { // Locate plugin and load pacjage.json try { - var res = resolve.sync(name + '/package.json', { basedir: baseDir }); + var res = resolve.sync(that.npmId + '/package.json', { basedir: baseDir }); that.baseDir = path.dirname(res); that.packageInfos = require(res); } catch (err) { - if (err.code != 'MODULE_NOT_FOUND') throw err; + // Wait on https://github.com/substack/node-resolve/pull/81 to be merged + if (err.message.indexOf('Cannot find module') < 0) throw err; that.packageInfos = undefined; that.content = undefined; @@ -51,14 +55,14 @@ BookPlugin.prototype.load = function() { } // Load plugin JS content - that.content = require(resolve.sync(name, { basedir: baseDir })); + that.content = require(resolve.sync(that.npmId, { basedir: baseDir })); return true; }) .then(that.validate); - this.log.info.log('Loading plugin "' + this.id + '" ...'); - return this.log.info.promise('', promise); + this.log.info('Loading plugin "' + this.id + '" ...'); + return this.log.info.promise(p); }; |