Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add hook *before:step-functions-offline:start* #313

Merged
merged 9 commits into from
Feb 27, 2018

Conversation

vkkis93
Copy link
Contributor

@vkkis93 vkkis93 commented Jan 25, 2018

What did you implement:

Integration serverless-step-functions-offline with serverless-webpack

How did you implement it:

Just add hook 'before:step-functions-offline:start'

How can we verify it:

Run serverless-step-functions-offline plugin in serverless project where serverless-webpack will be first runned

plugins:
   - serverless-webpack
   ...
   - serverless-step-functions-offline

Todos:

  • Write tests
  • Write documentation
  • Fix linting errors
  • Make sure code coverage hasn't dropped
  • Provide verification config / commands / resources
  • Enable "Allow edits from maintainers" for this PR
  • Update the messages below

Is this ready for review?: YES
Is it a breaking change?: NO

@HyperBrain
Copy link
Member

Hey @vkkis93 , nice addition 👍 Will be part of the next release.

Are there any caveats if using step-functions offline together with serverless-offline, or is that not possible?

index.js Outdated
@@ -153,6 +153,9 @@ class ServerlessWebpack {
.then(this.prepareOfflineInvoke)
.then(this.wpwatch),

'before:step-functions-offline:start': () => BbPromise.bind(this)
.then(this.validate)
.then(this.compile)
Copy link
Member

@HyperBrain HyperBrain Jan 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Watch will automatically watch for source changes. Both functionalities (offline watch and invoke local watch) set the base directory for the execution properly, e.g. for serverless-offline the location parameter is set correctly.

If there is something similar for the step-functions that needs to be done, we had to add a different "watch" or "prepare" function for step (e.g. stepWatch).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using .then(this.validate).then(this.compile) need to create separate function for plugin ?

Copy link
Member

@HyperBrain HyperBrain Jan 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only if we want to support watch mode and if step-offline needs to know the compiled directory, then you can do:

.then(this.validate)
.then(this.prepareStepOffline)   <<<--- see here
.then(this.wpwatch)

The new prepareStepOffline function should then do something similar as https://github.com/serverless-heaven/serverless-webpack/blob/master/lib/prepareOfflineInvoke.js, only that it prepares the root folder for the step-offline plugin.

Otherwise the step-offline will just run on the uncompiled code.

Copy link
Contributor Author

@vkkis93 vkkis93 Jan 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need only compile code once, run step-offline and stop process.
I don't need to have watch mode
About compiled directory, user will indicate the path to directory by himself in plugin settings.

Referring to my requirements - need to change something or this code makes sense?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense with the compile, yes.

However:

About compiled directory, user will indicate the path to directory by himself.

That will not really work out, if you set package: individually. Then the compiled code will then be distributed. I think you need a "prepare" function because for the offline, it has to be set to service packaging (then the output directory is ".webpack/service") like in the prepareOffline.

With individual packaging it is ".webpack/" which is not predictable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you give me the link to your plugin. Maybe I have some time over the weekend to have a look, if we can combine this in an easy and compatible way there.

Copy link
Contributor Author

@vkkis93 vkkis93 Jan 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HyperBrain but looks like your approach very good.
Makes sense to rewrite it.
Only one question, serverless-webpack compiles all functions which described in section functions in serverless.yml ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great,
I update this pull request to Is this ready for review?: NO at this moment.
When I will rewrite code, I will notify you

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I'm already excited 😄

@vkkis93
Copy link
Contributor Author

vkkis93 commented Feb 20, 2018

Hi @HyperBrain .
I have changed my code and now PR is ready for review.
The only one problem I see it's coveralls.
Need to write some tests on my new file ?

Copy link
Member

@HyperBrain HyperBrain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @vkkis93 , happy to see this done now ;-)

Please add a unit test (similar to the one for serverless-offline prepare) to have the coverage up again.

index.js Outdated
@@ -153,6 +155,10 @@ class ServerlessWebpack {
.then(this.prepareOfflineInvoke)
.then(this.wpwatch),

'before:step-functions-offline:start': () => BbPromise.bind(this)
.then(this.validate)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You already spawn the webpack:validate in the prepareStepOfflineInvoke function, so you can remove the line here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh, you're right.
I missed that

@vkkis93
Copy link
Contributor Author

vkkis93 commented Feb 21, 2018

@HyperBrain can you show the example of unit tests for serverless-offline ?

@HyperBrain
Copy link
Member

Oops. Just saw that these unit test are also missing.

I will add the prepare unit tests for StepOffline to this PR, so you don't have to take care of them 😄

@vkkis93
Copy link
Contributor Author

vkkis93 commented Feb 21, 2018

@HyperBrain great news ☺️

@vkkis93
Copy link
Contributor Author

vkkis93 commented Feb 26, 2018

Hi @HyperBrain .
What should be done in order to close this PR?

@HyperBrain
Copy link
Member

I'll finish it tomorrow and merge it. Sorry for the delay, was busy over the weekend ;-)

const path = require('path');

/**
* Special settings for use with serverless-offline.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be step-functions-offline instead of serverless-offline.

Copy link
Contributor Author

@vkkis93 vkkis93 Feb 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed
Should be serverless-step-functions-offline (it's name of plugin)

@vkkis93
Copy link
Contributor Author

vkkis93 commented Feb 27, 2018

Thanks a lot

@HyperBrain HyperBrain added this to the 4.4.0 milestone Feb 27, 2018
@HyperBrain
Copy link
Member

The new implementation is now covered 100%. The decrease is because a different unrelated file is not correctly tested. I will merge this PR now and fix the other unit test in a separate PR.
@vkkis93 Thanks again for the PR 👍

@HyperBrain HyperBrain merged commit d38a385 into serverless-heaven:master Feb 27, 2018
@j0k3r
Copy link
Member

j0k3r commented Feb 27, 2018

@vkkis93 Good job!

@stephanschubert
Copy link

👍 Looking forward to 4.4.0

@HyperBrain
Copy link
Member

Released with 4.4.0

jamesmbourne pushed a commit to jamesmbourne/serverless-webpack that referenced this pull request Oct 15, 2019
add hook *before:step-functions-offline:start*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants