Skip to content

Commit

Permalink
Allow plugins to be stored as devDependencies too.
Browse files Browse the repository at this point in the history
When using a custom server, I would like to store only the output of hexo's build process, and no extra dependencies, and the way I can do that is by storing the plugins in devDep and running npm install --production to get the server dependencies.
  • Loading branch information
lewiscowper committed May 11, 2017
1 parent aeac61d commit f6e20de
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/hexo/load_plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function loadModuleList(ctx) {
// Read package.json and find dependencies
return fs.readFile(packagePath).then(function(content) {
var json = JSON.parse(content);
var deps = json.dependencies || {};
var deps = json.dependencies || json.devDependencies || {};

return Object.keys(deps);
});
Expand Down
28 changes: 28 additions & 0 deletions test/scripts/hexo/load_plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@ describe('Load plugins', () => {
return fs.writeFile(pathFn.join(hexo.base_dir, 'package.json'), JSON.stringify(pkg, null, ' '));
}

function createPackageFileWithDevDeps(...args) {
var pkg = {
name: 'hexo-site',
version: '0.0.0',
private: true,
devDependencies: {}
};

for (var i = 0, len = args.length; i < len; i++) {
pkg.devDependencies[args[i]] = '*';
}

return fs.writeFile(pathFn.join(hexo.base_dir, 'package.json'), JSON.stringify(pkg, null, ' '));
}

hexo.env.init = true;
hexo.theme_script_dir = pathFn.join(hexo.base_dir, 'themes', 'test', 'scripts');

Expand Down Expand Up @@ -76,6 +91,19 @@ describe('Load plugins', () => {
});
});

it('load devDep plugins', () => {
var name = 'hexo-plugin-test';
var path = pathFn.join(hexo.plugin_dir, name, 'index.js');

return Promise.all([
createPackageFileWithDevDeps(name),
fs.writeFile(path, script)
]).then(() => loadPlugins(hexo)).then(() => {
validate(path);
return fs.unlink(path);
});
});

it('specify plugin list in config', () => {
var names = ['hexo-plugin-test', 'another-plugin'];
var paths = names.map(name => pathFn.join(hexo.plugin_dir, name, 'index.js'));
Expand Down

0 comments on commit f6e20de

Please sign in to comment.