Skip to content
This repository has been archived by the owner on Mar 27, 2020. It is now read-only.

Commit

Permalink
Add iopipe wrapper to package excludes (#10)
Browse files Browse the repository at this point in the history
Closes #9
  • Loading branch information
kolanos authored Apr 5, 2019
1 parent 2c80863 commit f335622
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
5 changes: 4 additions & 1 deletion example/handler.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
def handler(event, context):
if not hasattr(context, "iopipe") or not hasattr(context.iopipe, "mark"):
if not hasattr(context, "iopipe"):
raise Exception("No iopipe.")

if not hasattr(context.iopipe, "mark"):
raise Exception("No plugins")

return 200
25 changes: 25 additions & 0 deletions example/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,45 @@ custom:
functions:
layer-nodejs610:
handler: handler.handler
package:
exclude:
- ./**
include:
- handler.js
runtime: nodejs6.10

layer-nodejs810:
handler: handler.handler
package:
exclude:
- ./**
include:
- handler.js
runtime: nodejs8.10

layer-python27:
handler: handler.handler
package:
exclude:
- ./**
include:
- handler.py
runtime: python2.7

layer-python36:
handler: handler.handler
package:
exclude:
- ./**
include:
- handler.py
runtime: python3.6

layer-python37:
handler: handler.handler
package:
exclude:
- ./**
include:
- handler.py
runtime: python3.7
18 changes: 17 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export default class IOpipeLayerPlugin {
this.options = options;

this.hooks = {
"after:deploy:function:packageFunction": this.cleanup.bind(this),
"after:package:createDeploymentArtifacts": this.cleanup.bind(this),
"before:deploy:function:packageFunction": this.run.bind(this),
"before:package:createDeploymentArtifacts": this.run.bind(this)
};
}
Expand Down Expand Up @@ -64,7 +66,8 @@ export default class IOpipeLayerPlugin {
environment = {},
handler,
runtime = _.get(this.serverless.service, "provider.runtime"),
layers = []
layers = [],
package: pkg = {}
} = funcDef;

if (!this.config.token && !environment.IOPIPE_TOKEN) {
Expand Down Expand Up @@ -115,6 +118,7 @@ export default class IOpipeLayerPlugin {
funcDef.environment = environment;

funcDef.handler = this.getHandlerWrapper(runtime, handler);
funcDef.package = this.updatePackageExcludes(runtime, pkg);
}

private getLayerArn(runtime: string, region: string) {
Expand Down Expand Up @@ -160,6 +164,18 @@ export default class IOpipeLayerPlugin {
fs.removeSync(helperPath);
}
}

private updatePackageExcludes(runtime: string, pkg: any) {
if (!runtime.match("nodejs")) {
return pkg;
}

const { exclude = [] } = pkg;
exclude.push("!iopipe_wrapper.js");
pkg.exclude = exclude;

return pkg;
}
}

module.exports = IOpipeLayerPlugin;

0 comments on commit f335622

Please sign in to comment.