Skip to content

Commit e27bce2

Browse files
committed
test and fix broken support for invoke local as of [email protected]
1 parent ca581e7 commit e27bce2

File tree

8 files changed

+425
-365
lines changed

8 files changed

+425
-365
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# ⚡ 0.3.4
2+
3+
- fix a `npx serverless invoke local` for versions of serverless framework `1.40.*` which now emit `package` events as within `invokeLocal` events.
4+
15
# ⚡ 0.3.3
26

37
- bump [lambda-rust](https://hub.docker.com/r/softprops/lambda-rust/) docker version to 0.2.1-rust-1.34.0 to gain [new rust 1.34.0 features](https://blog.rust-lang.org/2019/04/11/Rust-1.34.0.html).

index.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ const RUST_RUNTIME = "rust";
1212
const BASE_RUNTIME = "provided";
1313
const NO_OUTPUT_CAPTURE = { stdio: ["ignore", process.stdout, process.stderr] };
1414

15+
function includeInvokeHook(serverlessVersion) {
16+
let [major, minor] = serverlessVersion.split('.')
17+
let majorVersion = parseInt(major)
18+
let minorVersion = parseInt(minor)
19+
return majorVersion === 1 && minorVersion >= 38 && minorVersion < 40;
20+
}
21+
1522
/** assumes docker is on the host's execution path */
1623
class RustPlugin {
1724
constructor(serverless, options) {
@@ -21,8 +28,10 @@ class RustPlugin {
2128
this.hooks = {
2229
"before:package:createDeploymentArtifacts": this.build.bind(this),
2330
"before:deploy:function:packageFunction": this.build.bind(this),
24-
'before:invoke:local:invoke': this.build.bind(this),
2531
};
32+
if (includeInvokeHook(serverless.version)) {
33+
this.hooks['before:invoke:local:invoke'] = this.build.bind(this);
34+
}
2635
this.custom = Object.assign(
2736
{
2837
cargoFlags: "",
@@ -89,7 +98,7 @@ class RustPlugin {
8998
const func = service.getFunction(funcName);
9099
const runtime = func.runtime || service.provider.runtime;
91100
if (runtime != RUST_RUNTIME) {
92-
// skip functions which don't apply
101+
// skip functions which don't apply to rust
93102
return;
94103
}
95104
rustFunctionsFound = true;

package-lock.json

Lines changed: 16 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "serverless-rust",
3-
"version": "0.3.3",
3+
"version": "0.3.4",
44
"description": "Serverless framework plugin for Rustlang applications",
55
"main": "index.js",
66
"scripts": {
@@ -25,7 +25,7 @@
2525
"dependencies": {
2626
"fs-copy-file-sync": "^1.1.1",
2727
"fs-extra": "^7.0.1",
28-
"serverless": "^1.40.0",
28+
"serverless": "^1.41.1",
2929
"test": "^0.6.0"
3030
},
3131
"devDependencies": {

0 commit comments

Comments
 (0)