diff --git a/lib/hexo/load_plugins.js b/lib/hexo/load_plugins.js index 62eb69394e..537dac4796 100644 --- a/lib/hexo/load_plugins.js +++ b/lib/hexo/load_plugins.js @@ -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); }); diff --git a/test/scripts/hexo/load_plugins.js b/test/scripts/hexo/load_plugins.js index 4d5f695274..443eba2bd5 100644 --- a/test/scripts/hexo/load_plugins.js +++ b/test/scripts/hexo/load_plugins.js @@ -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'); @@ -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'));