Skip to content
Permalink
Browse files
fix: PluginInfoProvider for scoped plugins (#94)
* fix: PluginInfoProvider for scoped plugins
* Add test for PluginInfoProvider /w scoped plugin
* Normalize paths to use backslash on Windows
  • Loading branch information
raphinesse authored and erisu committed Nov 7, 2019
1 parent 6583aef commit d53d2662e96d4b0e9dac99623db17439cda6ce4f
Showing 3 changed files with 20 additions and 12 deletions.
@@ -28,6 +28,10 @@ describe('PluginInfoProvider', function () {
var pluginInfoProvider = new PluginInfoProvider();
var plugins = pluginInfoProvider.getAllWithinSearchPath(pluginsDir);
expect(plugins.length).not.toBe(0);
expect(plugins).toContain(jasmine.objectContaining({
id: 'org.test.scoped',
dir: path.join(pluginsDir, '@scope/test')
}));
});
});
});
@@ -0,0 +1 @@
<plugin id="org.test.scoped" />
@@ -21,6 +21,7 @@ var fs = require('fs-extra');
var path = require('path');
var PluginInfo = require('./PluginInfo');
var events = require('../events');
const glob = require('glob');

function PluginInfoProvider () {
this._cache = {};
@@ -62,19 +63,21 @@ function getAllHelper (absPath, provider) {
if (fs.existsSync(path.join(absPath, 'plugin.xml'))) {
return [provider.get(absPath)];
}
var subdirs = fs.readdirSync(absPath);
var plugins = [];
subdirs.forEach(function (subdir) {
var d = path.join(absPath, subdir);
if (fs.existsSync(path.join(d, 'plugin.xml'))) {
try {
plugins.push(provider.get(d));
} catch (e) {
events.emit('warn', 'Error parsing ' + path.join(d, 'plugin.xml.\n' + e.stack));
}

// Match normal and scoped plugins
const pluginXmlPaths = glob.sync('{,@*/}*/plugin.xml', {
cwd: absPath,
nodir: true,
absolute: true
}).map(path.normalize);

return pluginXmlPaths.map(pluginXmlPath => {
try {
return provider.get(path.dirname(pluginXmlPath));
} catch (err) {
events.emit('warn', `Error parsing ${pluginXmlPath}:\n${err.stack}`);
}
});
return plugins;
}).filter(p => p);
}

module.exports = PluginInfoProvider;

0 comments on commit d53d266

Please sign in to comment.