mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-24 19:32:07 +00:00
Improve plugin loading to not fake module errors
This commit is contained in:
@@ -32,6 +32,7 @@ function loadPlugin(book, plugin) {
|
||||
var p = Promise()
|
||||
.then(function() {
|
||||
var packageContent;
|
||||
var packageMain;
|
||||
var content;
|
||||
|
||||
// Locate plugin and load package.json
|
||||
@@ -49,15 +50,20 @@ function loadPlugin(book, plugin) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Load plugin JS content
|
||||
// Locate the main package
|
||||
try {
|
||||
content = require(pkgPath);
|
||||
} catch(err) {
|
||||
// It's no big deal if the plugin doesn't have an "index.js"
|
||||
// (For example: themes)
|
||||
if (isModuleNotFound(err)) {
|
||||
content = {};
|
||||
} else {
|
||||
var indexJs = path.normalize(packageContent.main || 'index.js');
|
||||
packageMain = resolve.sync('./' + indexJs, { basedir: pkgPath });
|
||||
} catch (err) {
|
||||
if (!isModuleNotFound(err)) throw err;
|
||||
packageMain = undefined;
|
||||
}
|
||||
|
||||
// Load plugin JS content
|
||||
if (packageMain) {
|
||||
try {
|
||||
content = require(packageMain);
|
||||
} catch(err) {
|
||||
throw new error.PluginError(err, {
|
||||
plugin: name
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user