diff --git a/src/plugins.js b/src/plugins.js index de328887eb..41cd1da7b8 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -297,25 +297,26 @@ Plugins.normalise = function (apiReturn, callback) { }); }; +Plugins.nodeModulesPath = path.join(__dirname, '../node_modules'); + Plugins.showInstalled = function (callback) { - var nodeModulesPath = path.join(__dirname, '../node_modules'); var pluginNamePattern = /^(@.*?\/)?nodebb-(theme|plugin|widget|rewards)-.*$/; async.waterfall([ function (next) { - fs.readdir(nodeModulesPath, next); + fs.readdir(Plugins.nodeModulesPath, next); }, function (dirs, next) { var pluginPaths = []; async.each(dirs, function (dirname, next) { - var dirPath = path.join(nodeModulesPath, dirname); + var dirPath = path.join(Plugins.nodeModulesPath, dirname); async.waterfall([ function (cb) { fs.stat(dirPath, function (err, stats) { if (err && err.code !== 'ENOENT') { - return next(err); + return cb(err); } if (err || !stats.isDirectory()) { return next(); @@ -361,7 +362,7 @@ Plugins.showInstalled = function (callback) { function (dirs, next) { dirs = dirs.map(function (dir) { - return path.join(nodeModulesPath, dir); + return path.join(Plugins.nodeModulesPath, dir); }); var plugins = []; diff --git a/test/mocks/plugin_modules/@nodebb/another-thing/package.json b/test/mocks/plugin_modules/@nodebb/another-thing/package.json new file mode 100644 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/test/mocks/plugin_modules/@nodebb/another-thing/package.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/test/mocks/plugin_modules/@nodebb/another-thing/plugin.json b/test/mocks/plugin_modules/@nodebb/another-thing/plugin.json new file mode 100644 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/test/mocks/plugin_modules/@nodebb/another-thing/plugin.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/test/mocks/plugin_modules/@nodebb/nodebb-plugin-abc/package.json b/test/mocks/plugin_modules/@nodebb/nodebb-plugin-abc/package.json new file mode 100644 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/test/mocks/plugin_modules/@nodebb/nodebb-plugin-abc/package.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/test/mocks/plugin_modules/@nodebb/nodebb-plugin-abc/plugin.json b/test/mocks/plugin_modules/@nodebb/nodebb-plugin-abc/plugin.json new file mode 100644 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/test/mocks/plugin_modules/@nodebb/nodebb-plugin-abc/plugin.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/test/mocks/plugin_modules/nodebb-plugin-xyz/package.json b/test/mocks/plugin_modules/nodebb-plugin-xyz/package.json new file mode 100644 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/test/mocks/plugin_modules/nodebb-plugin-xyz/package.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/test/mocks/plugin_modules/nodebb-plugin-xyz/plugin.json b/test/mocks/plugin_modules/nodebb-plugin-xyz/plugin.json new file mode 100644 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/test/mocks/plugin_modules/nodebb-plugin-xyz/plugin.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/test/mocks/plugin_modules/something-else/package.json b/test/mocks/plugin_modules/something-else/package.json new file mode 100644 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/test/mocks/plugin_modules/something-else/package.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/test/mocks/plugin_modules/something-else/plugin.json b/test/mocks/plugin_modules/something-else/plugin.json new file mode 100644 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/test/mocks/plugin_modules/something-else/plugin.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/test/plugins.js b/test/plugins.js index caccbe2851..40c6c9c97f 100644 --- a/test/plugins.js +++ b/test/plugins.js @@ -94,6 +94,23 @@ describe('Plugins', function () { }); }); + it('should show installed plugins', function (done) { + var nodeModulesPath = plugins.nodeModulesPath; + plugins.nodeModulesPath = path.join(__dirname, './mocks/plugin_modules'); + + plugins.showInstalled(function (err, pluginsData) { + assert.ifError(err); + var paths = pluginsData.map(function (plugin) { + return path.relative(plugins.nodeModulesPath, plugin.path).replace(/\\/g, '/'); + }); + assert(paths.indexOf('nodebb-plugin-xyz') > -1); + assert(paths.indexOf('@nodebb/nodebb-plugin-abc') > -1); + + plugins.nodeModulesPath = nodeModulesPath; + done(); + }); + }); + describe('install/activate/uninstall', function () { var latest; var pluginName = 'nodebb-plugin-imgur';