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 sls plugin install -n @scoped/package #5736

Merged
merged 4 commits into from
Jan 22, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/plugins/plugin/install/install.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ class PluginInstall {
} }


install() { install() {
const pluginInfo = _.split(this.options.name, '@', 2); let pluginInfo;
if (this.options.name.startsWith('@')) {
pluginInfo = _.split(this.options.name.slice(1), '@', 2);
pluginInfo[0] = `@${pluginInfo[0]}`;
} else {
pluginInfo = _.split(this.options.name, '@', 2);
}
this.options.pluginName = pluginInfo[0]; this.options.pluginName = pluginInfo[0];
this.options.pluginVersion = pluginInfo[1] || 'latest'; this.options.pluginVersion = pluginInfo[1] || 'latest';


Expand Down
42 changes: 42 additions & 0 deletions lib/plugins/plugin/install/install.test.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ describe('PluginInstall', () => {
let consoleLogStub; let consoleLogStub;
let serverlessErrorStub; let serverlessErrorStub;
const plugins = [ const plugins = [
{
name: '@scope/serverless-plugin-1',
description: 'Scoped Serverless Plugin 1',
githubUrl: 'https://github.com/serverless/serverless-plugin-1',
},
{ {
name: 'serverless-plugin-1', name: 'serverless-plugin-1',
description: 'Serverless Plugin 1', description: 'Serverless Plugin 1',
Expand Down Expand Up @@ -157,6 +162,28 @@ describe('PluginInstall', () => {
}); });
}); });


it('should install a scoped plugin if it can be found in the registry', () => {
// serverless.yml
const serverlessYml = {
service: 'plugin-service',
provider: 'aws',
};
serverless.utils
.writeFileSync(serverlessYmlFilePath, YAML.dump(serverlessYml));

pluginInstall.options.name = '@scope/serverless-plugin-1';

return expect(pluginInstall.install()).to.be.fulfilled.then(() => {
expect(validateStub.calledOnce).to.equal(true);
expect(getPluginsStub.calledOnce).to.equal(true);
expect(pluginInstallStub.calledOnce).to.equal(true);
expect(consoleLogStub.called).to.equal(true);
expect(serverlessErrorStub.calledOnce).to.equal(false);
expect(addPluginToServerlessFileStub.calledOnce).to.equal(true);
expect(installPeerDependenciesStub.calledOnce).to.equal(true);
});
});

it('should not install the plugin if it can not be found in the registry', () => { it('should not install the plugin if it can not be found in the registry', () => {
// serverless.yml // serverless.yml
const serverlessYml = { const serverlessYml = {
Expand Down Expand Up @@ -192,6 +219,21 @@ describe('PluginInstall', () => {
}); });
}); });


it('should apply the latest version if you can not get the ' +
'version from name option even if scoped', () => {
const serverlessYml = {
service: 'plugin-service',
provider: 'aws',
};
serverless.utils
.writeFileSync(serverlessYmlFilePath, YAML.dump(serverlessYml));
pluginInstall.options.name = '@scope/serverless-plugin-1';
return expect(pluginInstall.install()).to.be.fulfilled.then(() => {
expect(pluginInstall.options.pluginName).to.be.equal('@scope/serverless-plugin-1');
expect(pluginInstall.options.pluginVersion).to.be.equal('latest');
});
});

it('should apply the specified version if you can get the version from name option', () => { it('should apply the specified version if you can get the version from name option', () => {
const serverlessYml = { const serverlessYml = {
service: 'plugin-service', service: 'plugin-service',
Expand Down