serverless-heaven/serverless-webpack

Integrate with "Serverless invoke local" and change the "webpack invoke" command

HyperBrain opened this issue ยท 8 comments

This is a Feature Proposal

Description

Serverless offers a fully working local invoke command that handles all possible
kinds of invocations, sets the function's environment correctly and much more.

There is no need to have a separate webpack invoke command that replicates (only)
parts of this functionality and binds resources to maintain it properly.

It would be better to integrate seamlessly with local invoke by hooking the important
lifecycle events exposed by the command. Finally, serverless invoke local should
invoke the function after the webpack compile has been triggered as part of the lifecycle
hooks in place.

To make it completely seamless, the webpack invoke command should techincally just use Serverless'
pluginManager to spawn the invoke local command like this: this.serverless.pluginManager.spawn('invoke:local').

This solution would also make the invocation provider independent as Serverless fully takes care of that already.

Related issue(s):
#128 (arbitrary provider support)

During the implementation I saw that it could make sense to couple the watch command with the serverless invoke local too, so that Serverless takes care of setting the environment and other stuff automatically in that case.
I tend to change that within the context of the attached PR too.
Are there any objections?

@benjaminwood @hassankhan The basic implementation is finished (support of "serverless invoke local"), i.e. sls invoke local should now work with the plugin. I did a few tests with my test project. Could you also verify that it works with this PR (#153)?

I will finish it over the weekend and remove the now obsolete code, adapt the docs and write unit tests.

I'm away on holiday for the weekend but I'll try and give it a go, seems simple enough to test ๐Ÿ˜„

This is great, thanks @HyperBrain! It does work for me, though I did run into one snag.

When using the invoke local command with the --path (-p) flag, relative file paths will not be found because serverless will end up looking in the build directory (.webpack) later on.

I took a stab at fixing this and I'm happy to PR it if I'm headed down the right path: https://github.com/benjaminwood/serverless-webpack/commit/37086eddb78cd0f0de66938de6188606dc2e36d8

Couldn't think of a good name for the function. Also, I'm not sure that this should go in the utils file. Happy to make revisions! Let me know what you think.

Hey @benjaminwood . Thanks a lot, good catch ๐Ÿ‘ . In general, it is better to open a PR instead of linking a commit - regardless if the approach is feasible or not. It's just easier to discuss a possible solution/implementation within a PR in GitHub - as easy as it is to merge or revoke the PR later. This will keep the main issue clean (the PR candidates are still listed if they are linked correctly) and put the implementation specific discussion near to the implementation itself.

So just open a PR ๐Ÿ˜ƒ - I added templates for PRs recently, so the PR description will additionally contain important info (e.g. if it is ready for review/discussion, etc.). Target the PR to the v3.0.0-invoke-local branch.

... and I'm really glad to hear that my changes work (with exception of the path issue)

@hassankhan No hurry, enjoy your holidays ๐Ÿ˜ƒ

Thanks @HyperBrain I've opened a PR: #156

@benjaminwood Cool ๐Ÿ™Œ . I commented there.