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
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+49 −1
Diff settings

Always

Just for now

@@ -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';


@@ -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',
@@ -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 = {
@@ -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',
ProTip! Use n and p to navigate between commits in a pull request.