diff --git a/lib/plugins/package/lib/packageService.js b/lib/plugins/package/lib/packageService.js index 1b1304c272e..dd158638ab0 100644 --- a/lib/plugins/package/lib/packageService.js +++ b/lib/plugins/package/lib/packageService.js @@ -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'); @@ -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; @@ -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() {