Skip to content

Commit

Permalink
fix(Packaging): Validate package.artifact paths
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Jul 8, 2021
1 parent 993591a commit 21c0fed
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions lib/plugins/package/lib/packageService.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const path = require('path');
const fsp = require('fs').promises;
const globby = require('globby');
const _ = require('lodash');
const micromatch = require('micromatch');
Expand Down Expand Up @@ -75,7 +76,20 @@ module.exports = {
this.serverless.cli.log(`Packaging disabled for function: "${functionName}"`);
return;
}
if (functionObject.package.artifact) return;
if (functionObject.package.artifact) {
try {
await fsp.access(
path.resolve(this.serverless.serviceDir, functionObject.package.artifact)
);
return;
} catch (error) {
throw new ServerlessError(
'Cannot access package artifact at ' +
`"${functionObject.package.artifact}" (for "${functionName}"): ${error.message}`,
'INVALID_PACKAGE_ARTIFACT_PATH'
);
}
}
if (functionObject.package.individually || this.serverless.service.package.individually) {
await this.packageFunction(functionName);
return;
Expand All @@ -93,7 +107,23 @@ module.exports = {
);

await Promise.all(packagePromises);
if (shouldPackageService && !this.serverless.service.package.artifact) await this.packageAll();
if (shouldPackageService) {
if (this.serverless.service.package.artifact) {
try {
await fsp.access(
path.resolve(this.serverless.serviceDir, this.serverless.service.package.artifact)
);
return;
} catch (error) {
throw new ServerlessError(
'Cannot access package artifact at ' +
`"${this.serverless.service.package.artifact}": ${error.message}`,
'INVALID_PACKAGE_ARTIFACT_PATH'
);
}
}
await this.packageAll();
}
},

async packageAll() {
Expand Down

0 comments on commit 21c0fed

Please sign in to comment.