mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-23 02:53:29 +00:00
Start fixing order of plugins in dependencies
This commit is contained in:
@@ -18,6 +18,9 @@ var Plugin = Immutable.Record({
|
||||
// Depth of this plugin in the dependency tree
|
||||
depth: Number(0),
|
||||
|
||||
// Parent depending on this plugin
|
||||
parent: String(),
|
||||
|
||||
// Content of the "package.json"
|
||||
package: Immutable.Map(),
|
||||
|
||||
@@ -49,6 +52,10 @@ Plugin.prototype.getDepth = function() {
|
||||
return this.get('depth');
|
||||
};
|
||||
|
||||
Plugin.prototype.getParent = function() {
|
||||
return this.get('parent');
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the ID on NPM for this plugin
|
||||
* @return {String}
|
||||
|
||||
@@ -8,21 +8,21 @@ var Plugin = require('../models/plugin');
|
||||
var PREFIX = require('../constants/pluginPrefix');
|
||||
|
||||
/**
|
||||
Validate if a package name is a GitBook plugin
|
||||
|
||||
@return {Boolean}
|
||||
*/
|
||||
* Validate if a package name is a GitBook plugin
|
||||
*
|
||||
* @return {Boolean}
|
||||
*/
|
||||
function validateId(name) {
|
||||
return name && name.indexOf(PREFIX) === 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
List all packages installed inside a folder
|
||||
|
||||
@param {String} folder
|
||||
@return {OrderedMap<String:Plugin>}
|
||||
*/
|
||||
* List all packages installed inside a folder
|
||||
*
|
||||
* @param {String} folder
|
||||
* @return {OrderedMap<String:Plugin>}
|
||||
*/
|
||||
function findInstalled(folder) {
|
||||
var options = {
|
||||
dev: false,
|
||||
@@ -31,7 +31,7 @@ function findInstalled(folder) {
|
||||
};
|
||||
var results = Immutable.OrderedMap();
|
||||
|
||||
function onPackage(pkg, isRoot) {
|
||||
function onPackage(pkg, parent) {
|
||||
if (!pkg.name) return;
|
||||
|
||||
var name = pkg.name;
|
||||
@@ -43,18 +43,19 @@ function findInstalled(folder) {
|
||||
var pluginName = name.slice(PREFIX.length);
|
||||
|
||||
if (!validateId(name)){
|
||||
if (!isRoot) return;
|
||||
if (parent) return;
|
||||
} else {
|
||||
results = results.set(pluginName, Plugin({
|
||||
name: pluginName,
|
||||
version: version,
|
||||
path: pkgPath,
|
||||
depth: depth
|
||||
depth: depth,
|
||||
parent: parent
|
||||
}));
|
||||
}
|
||||
|
||||
Immutable.Map(dependencies).forEach(function(dep) {
|
||||
onPackage(dep);
|
||||
onPackage(dep, pluginName);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -77,7 +78,7 @@ function findInstalled(folder) {
|
||||
var module_folder = path.join(node_modules, module);
|
||||
return Promise.nfcall(readInstalled, module_folder, options)
|
||||
.then(function(data) {
|
||||
onPackage(data, true);
|
||||
onPackage(data);
|
||||
});
|
||||
});
|
||||
})
|
||||
|
||||
@@ -5,11 +5,11 @@ var DEFAULT_PLUGINS = require('../constants/defaultPlugins');
|
||||
var sortPlugins = require('./sortPlugins');
|
||||
|
||||
/**
|
||||
List all plugins for a book
|
||||
|
||||
@param {List<PluginDependency>} deps
|
||||
@return {OrderedMap<Plugin>}
|
||||
*/
|
||||
* List all plugins for a book
|
||||
*
|
||||
* @param {List<PluginDependency>} deps
|
||||
* @return {OrderedMap<Plugin>}
|
||||
*/
|
||||
function listAll(deps) {
|
||||
// Extract list of plugins to disable (starting with -)
|
||||
var toRemove = deps
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
var listAll = require('./listAll');
|
||||
|
||||
/**
|
||||
List all plugin requirements for a book.
|
||||
It can be different from the final list of plugins,
|
||||
since plugins can have their own dependencies
|
||||
|
||||
@param {Book}
|
||||
@return {OrderedMap<Plugin>}
|
||||
*/
|
||||
* List all plugin requirements for a book.
|
||||
* It can be different from the final list of plugins,
|
||||
* since plugins can have their own dependencies
|
||||
*
|
||||
* @param {Book}
|
||||
* @return {OrderedMap<Plugin>}
|
||||
*/
|
||||
function listForBook(book) {
|
||||
var config = book.getConfig();
|
||||
var plugins = config.getPluginDependencies();
|
||||
|
||||
@@ -6,7 +6,8 @@ var loadPlugin = require('./loadPlugin');
|
||||
|
||||
|
||||
/**
|
||||
* Load a list of plugins in a book
|
||||
* Load all plugins in a book
|
||||
*
|
||||
* @param {Book}
|
||||
* @return {Promise<Map<String:Plugin>}
|
||||
*/
|
||||
@@ -19,12 +20,36 @@ function loadForBook(book) {
|
||||
.then(function(installed) {
|
||||
// Filter out plugins not listed of first level
|
||||
// (aka pre-installed plugins)
|
||||
installed = installed.filter(function(plugin) {
|
||||
/*installed = installed.filter(function(plugin) {
|
||||
return (
|
||||
// Plugin is a dependency of another one
|
||||
plugin.getDepth() > 0 ||
|
||||
|
||||
// Plugin is specified in "book.json"
|
||||
requirements.has(plugin.getName())
|
||||
);
|
||||
});
|
||||
});*/
|
||||
|
||||
// Insert installed plugins not listed in required
|
||||
var pluginsToLoad = installed.reduce(function(pluginSeq, plugin) {
|
||||
var name = plugin.getName();
|
||||
|
||||
if (requirements.has(name)) {
|
||||
return pluginSeq;
|
||||
}
|
||||
|
||||
var parentName = plugin.getParent();
|
||||
|
||||
|
||||
pluginSeq = pluginSeq.push([
|
||||
name,
|
||||
plugin
|
||||
]);
|
||||
|
||||
return pluginSeq;
|
||||
}, requirements.entrySeq());
|
||||
|
||||
|
||||
|
||||
// Log state
|
||||
logger.info.ln(installed.size + ' plugins are installed');
|
||||
|
||||
Reference in New Issue
Block a user