Skip to content

Commit

Permalink
perf(plugin): Add plugin version match check (#23)
Browse files Browse the repository at this point in the history
* fix(open): fix stub priority

* fix(plugin): fix plugin version match

* fix(plugin): fix version exist check
  • Loading branch information
xuchaoying authored Jul 30, 2019
1 parent 96cf8ba commit d968620
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/svrx/__tests__/spec/svrx.plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,8 @@ describe('Plugin System', () => {
});

describe('Builtin: open', () => {
const stub = sinon.stub(childProcess, 'exec');
it('basic usage', (done) => {
const stub = sinon.stub(childProcess, 'exec');
const svrx = createServer({
port: 3000,
open: true,
Expand Down
5 changes: 4 additions & 1 deletion packages/svrx/lib/plugin/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class PluginSystem {
const path = BUILTIN_PLUGIN.includes(name)
? libPath.join(__dirname, `./svrx-plugin-${name}`)
: pluginConfig.getInfo('path');
const version = pluginConfig.getInfo('version');
const hooks = pluginConfig.getInfo('hooks');
const assets = pluginConfig.getInfo('assets');
const inplace = pluginConfig.getInfo('inplace') || hooks || assets;
Expand Down Expand Up @@ -104,13 +105,15 @@ class PluginSystem {
return;
}
const svrxPattern = (pkg.engines && pkg.engines.svrx) || '*';
if (semver.satisfies(svrxPattern)) {
if ((!version || version === pkg.version) && semver.satisfies(svrxPattern)) {
resolve({
path: libPath.join(res.split(normalizedName)[0], normalizedName),
/* eslint-disable global-require, import/no-dynamic-require */
module: require(res),
pkg,
});
} else {
resolve(null);
}
},
);
Expand Down

0 comments on commit d968620

Please sign in to comment.