Skip to content

Commit

Permalink
Maintain original behavior and add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
mthenw committed Aug 14, 2019
1 parent f781340 commit f2f3c00
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -18,7 +18,7 @@ Serverless is an MIT open-source project, actively maintained by a full-time, ve

<a href="https://www.youtube.com/watch?v=-Nf0ui3qP2E" target="_blank">Watch the video overview here.</a>

[![serverless components notice](https://s3.amazonaws.com/assets.github.serverless/components/serverless_components_notice_dark.gif)](https://github.com/serverless/components)
[![serverless components notice](https://s3.amazonaws.com/assets.github.serverless/components/serverless_components_notice_dark.gif)](https://github.com/serverless/components)

## Contents

Expand Down
26 changes: 14 additions & 12 deletions lib/plugins/aws/deploy/lib/extendedValidate.js
Expand Up @@ -59,27 +59,29 @@ module.exports = {

if (!_.isEmpty(this.serverless.service.functions)) {
this.serverless.service.getAllFunctions().forEach(functionName => {
// By default assume service-level package
let artifactFileName = this.provider.naming.getServiceArtifactName();
let artifactFilePath = path.join(this.packagePath, artifactFileName);

const functionObject = this.serverless.service.getFunction(functionName);
const individually =
(_.has(functionObject, ['package', 'individually']) &&
functionObject.package.individually) ||
this.serverless.service.package.individually;

if (_.has(functionObject, ['package', 'artifact'])) {
// Use function-level artifact
artifactFilePath = functionObject.package.artifact;
artifactFileName = path.basename(artifactFilePath);
} else if (this.serverless.service.package.artifact) {
// Use service-level artifact
artifactFileName = artifactFilePath = this.serverless.service.package.artifact;
} else if (individually) {
// By default assume service-level package
let artifactFileName = this.provider.naming.getServiceArtifactName();
let artifactFilePath = path.join(this.packagePath, artifactFileName);

if (individually) {
// Use function-level generated artifact
artifactFileName = this.provider.naming.getFunctionArtifactName(functionName);
artifactFilePath = path.join(this.packagePath, artifactFileName);

if (_.has(functionObject, ['package', 'artifact'])) {
// Use function-level artifact
artifactFilePath = functionObject.package.artifact;
artifactFileName = path.basename(artifactFilePath);
}
} else if (this.serverless.service.package.artifact) {
// Use service-level artifact
artifactFileName = artifactFilePath = this.serverless.service.package.artifact;
}

if (!this.serverless.utils.fileExistsSync(artifactFilePath)) {
Expand Down
19 changes: 19 additions & 0 deletions lib/plugins/aws/deploy/lib/extendedValidate.test.js
Expand Up @@ -113,6 +113,25 @@ describe('extendedValidate', () => {
});
});

it('should use function package level generated artifact if functions is packaged individiually', () => {
awsDeploy.serverless.service.package.individually = false;
stateFileMock.service.functions = {
first: {
package: {
individually: true,
},
},
};
fileExistsSyncStub.returns(true);
readFileSyncStub.returns(stateFileMock);

return awsDeploy.extendedValidate().then(() => {
expect(fileExistsSyncStub.calledTwice).to.equal(true);
expect(readFileSyncStub.calledOnce).to.equal(true);
expect(fileExistsSyncStub.lastCall.args[0]).to.have.string('.serverless/first.zip');
});
});

it('should use function package level artifact when provided', () => {
stateFileMock.service.functions = {
first: {
Expand Down

0 comments on commit f2f3c00

Please sign in to comment.