UNPKG

serverless-aws-lambda

Version:

AWS Application Load Balancer and API Gateway - Lambda dev tool for Serverless. Allows Express synthax in handlers. Supports packaging, local invoking and offline ALB, APG, S3, SNS, SQS, DynamoDB Stream server mocking.

2 lines (1 loc) 2.48 kB
var g=!1,w=e=>{g=e},q=()=>g,f=(e,a)=>{g&&console.log(`\x1B[${e}m${a}\x1B[0m`)},L=e=>console.log(`\x1B[31m${e}\x1B[0m`),D=e=>f("32",e),G=e=>f("33",e),A=e=>f("36",e),O=e=>f("90",e),B=e=>f("94",e),M=e=>g?console.log(e):void 0,c={GREEN:D,YELLOW:G,CYAN:A,BR_BLUE:B,RED:L,GREY:O,setDebug:w,getDebug:q,info:M};var b=["exit","beforeExit","uncaughtException","unhandledRejection","SIGHUP","SIGINT","SIGQUIT","SIGILL","SIGTRAP","SIGABRT","SIGBUS","SIGFPE","SIGUSR1","SIGSEGV","SIGUSR2","SIGTERM"];var v=!1,C=[],U=e=>{if(!v){v=!0;for(let a of C)try{a(e)}catch(n){console.log(n),process.exitCode=1}process.exit()}};b.forEach(e=>{process.on(e,U)});function T(e){let a=new Set;return e.plugins&&(e.plugins=e.plugins.filter((n,l)=>typeof n!="object"||!n||!("name"in n)?!1:((!n.name||!n.name.length||typeof n.name!="string")&&(n.name="plugin-"+l,c.YELLOW(`Invalid plugin name at index ${l}`)),a.has(n.name)?n.name=n.name+l:a.add(n.name),!0))),async function({stop:l,lambdas:u,isDeploying:h,isPackaging:y,setEnv:S,stage:k,region:P,esbuild:I,serverless:x,resources:E,getServices:R,setServices:m}){let s={esbuild:e.esbuild??{},shimRequire:e.shimRequire,includeAwsSdk:e.includeAwsSdk,offline:{staticPath:e.offline?.staticPath,port:e.offline?.port},afterDeployCallbacks:[],afterPackageCallbacks:[]};e.services&&await m(e.services);let o={stop:l,lambdas:u,isDeploying:h,isPackaging:y,setEnv:S,stage:k,region:P,esbuild:I,serverless:x,options:e,config:s,resources:E,getServices:R,setServices:m};if(e.plugins){s.offline.onReady=async(i,t)=>{for(let r of e.plugins)if(r.offline?.onReady)try{await r.offline.onReady.call(o,i,t)}catch(d){c.RED(r.name),console.error(d)}},s.buildCallback=async(i,t)=>{for(let r of e.plugins)if(r.buildCallback)try{await r.buildCallback.call(o,i,t)}catch(d){c.RED(r.name),console.error(d),t||process.exit(1)}};let p=e.plugins.reduce((i,t)=>(t.offline?.request?.length&&i.push(...t.offline.request),i),[]);p?.length&&(s.offline.request=p.map(i=>(i.callback=i.callback.bind(o),i)));for(let i of e.plugins)if(i.onExit&&C.push(i.onExit.bind(o)),typeof i.afterDeploy=="function"&&s.afterDeployCallbacks.push(i.afterDeploy.bind(o)),typeof i.afterPackage=="function"&&s.afterPackageCallbacks.push(i.afterPackage.bind(o)),i.onInit)try{await i.onInit.call(o)}catch(t){c.RED(i.name),console.error(t)}}return s.afterDeployCallbacks.length||delete s.afterDeployCallbacks,s.afterPackageCallbacks.length||delete s.afterPackageCallbacks,s}}var Y=T;export{Y as default,T as defineConfig};