Skip to content

Commit

Permalink
Fix deploy command if package.individually set on a function-level
Browse files Browse the repository at this point in the history
  • Loading branch information
mthenw committed Aug 13, 2019
1 parent d4c8bc1 commit 3ceb0aa
Showing 1 changed file with 13 additions and 23 deletions.
36 changes: 13 additions & 23 deletions lib/plugins/aws/deploy/lib/extendedValidate.js
Expand Up @@ -57,20 +57,25 @@ module.exports = {
});
}

if (
!_.isEmpty(this.serverless.service.functions) &&
this.serverless.service.package.individually
) {
// artifact file validation (multiple function artifacts)
if (!_.isEmpty(this.serverless.service.functions)) {
this.serverless.service.getAllFunctions().forEach(functionName => {
let artifactFileName = this.provider.naming.getFunctionArtifactName(functionName);
// By default assume service-level package
let artifactFileName = this.provider.naming.getServiceArtifactName();
let artifactFilePath = path.join(this.packagePath, artifactFileName);

// check if an artifact is used in function package level
const functionObject = this.serverless.service.getFunction(functionName);
if (_.has(functionObject, ['package', 'artifact'])) {
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-levle artifact
artifactFileName = artifactFilePath = this.serverless.service.package.artifact;
} else if (individually) { // Use function-level generated artifact
artifactFileName = this.provider.naming.getFunctionArtifactName(functionName);
artifactFilePath = path.join(this.packagePath, artifactFileName);
}

if (!this.serverless.utils.fileExistsSync(artifactFilePath)) {
Expand All @@ -79,21 +84,6 @@ module.exports = {
);
}
});
} else if (!_.isEmpty(this.serverless.service.functions)) {
// artifact file validation (single service artifact)
let artifactFilePath;
let artifactFileName;
if (this.serverless.service.package.artifact) {
artifactFileName = artifactFilePath = this.serverless.service.package.artifact;
} else {
artifactFileName = this.provider.naming.getServiceArtifactName();
artifactFilePath = path.join(this.packagePath, artifactFileName);
}
if (!this.serverless.utils.fileExistsSync(artifactFilePath)) {
throw new this.serverless.classes.Error(
`No ${artifactFileName} file found in the package path you provided.`
);
}
}

return BbPromise.resolve();
Expand Down

0 comments on commit 3ceb0aa

Please sign in to comment.