Skip to content

Commit

Permalink
allow this plugin to be disabled per-function
Browse files Browse the repository at this point in the history
  • Loading branch information
sergioramos committed Sep 28, 2019
1 parent 5c0df2e commit 88f6fa8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ export default class ServerlessPlugin {
this.serverless.cli.log('running ncc');
const { servicePath } = this.serverless.config;
const slsService = this.serverless.service;
const ncc = (slsService && slsService.custom && slsService.custom.ncc) || {};
const gncc = (slsService && slsService.custom && slsService.custom.ncc) || {};
const dotServerlessPath = path.join(servicePath, '.serverless');
await makeDir(dotServerlessPath);

const packageFilesConfig = await parseServiceConfig(this.serverless);
const packagingPromises = packageFilesConfig.map(async ({ zip, files }) => {
const packagingPromises = packageFilesConfig.filter(Boolean).map(async (pkg) => {
const { zip, files, ncc: lncc = {} } = pkg;
const ncc = Object.assign({}, gncc, lncc);
// For now pass all ncc options directly to ncc. This has the benefit of testing out new
// ncc releases and changes quickly. Later it would be nice to add a validation step in between.
const codeCompilePromises = files.map(({ absPath }) =>
Expand Down Expand Up @@ -108,7 +110,12 @@ function setArtifacts(serverless: Serverless, serviceFilesConfigArr: IPackagingC
if (!individually) {
_.set(serverless, 'service.package.artifact', serviceFilesConfigArr[0].zip.absPath);
} else {
for (const { functionName, zip } of serviceFilesConfigArr) {
for (const cnf of serviceFilesConfigArr) {
if (!cnf) {
continue;
}

const { functionName, zip } = cnf;
if (!functionName) {
throw new Error('functionName cannot be empty when packaging individually');
}
Expand Down
7 changes: 6 additions & 1 deletion src/parse-service-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,19 @@ async function packageIndividually(serverless: Serverless): Promise<IPackagingCo
const functions: { [key: string]: ServerlessFunctionDefinition } = serverless.service.functions;
const serviceFilesConfigArrPromises = _.map(
functions,
async ({ name: serviceName, handler }, functionName) => {
async ({ name: serviceName, handler, custom = {} }, functionName) => {
if (custom && custom.ncc && custom.ncc.enabled === false) {
return;
}

const { name: fileName, absPath: filePath } = await handlerToFileDetails(
servicePath,
handler,
);
const zipName = `${serviceName}.zip`;
const zipPath = path.join(servicePath, `.serverless/${zipName}`);
return {
ncc: _.get(custom, 'ncc', {}),
functionName,
zip: {
absPath: zipPath,
Expand Down

0 comments on commit 88f6fa8

Please sign in to comment.