Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: PluginInfoProvider for scoped plugins #94

Merged
merged 3 commits into from
Nov 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions spec/PluginInfo/PluginInfoProvider.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}));
});
});
});
1 change: 1 addition & 0 deletions spec/fixtures/plugins/@scope/test/plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<plugin id="org.test.scoped" />
27 changes: 15 additions & 12 deletions src/PluginInfo/PluginInfoProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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;