Skip to content
New issue

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

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

Already on GitHub? # to your account

Purge handler module from require cache on watch #351

Merged
merged 3 commits into from
Mar 23, 2018

Conversation

HyperBrain
Copy link
Member

@HyperBrain HyperBrain commented Mar 20, 2018

What did you implement:

Closes #349

How did you implement it:

Before Serverless requires the handler, we purge any loaded ones from the require cache.
This forces Serverless to load a fresh handler from file, which is needed in case a watch compile happened. Otherwise the old module from the initial compile will be used.

How can we verify it:

  • Invoke any function locally in watch mode npx sls invoke local --function=XXXX --path=some-event.json --watch
  • Check the output
  • Change any functionality in the sources and save them to disk
  • Wait for the recompile and invocation thereafter
  • Check the output. Any changes in the sources should be reflected.

Todos:

  • Write tests
  • Write documentation (N/A)
  • 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

lib/utils.js Outdated
if (!_.includes(visitedModules, mod)) {
visitedModules.push(mod);
_.forEach(mod.children, function (child) {
traverse(child);
Copy link
Member Author

@HyperBrain HyperBrain Mar 20, 2018

Choose a reason for hiding this comment

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

To prevent stackoverflows I'll replace the recursive implementation with an iterative one (breadth or depth first search does not matter here).

@HyperBrain HyperBrain force-pushed the fix-local-invoke-watch branch from 702d3b3 to 68d649b Compare March 22, 2018 12:59
@HyperBrain HyperBrain added this to the 5.1.1 milestone Mar 22, 2018
@HyperBrain HyperBrain merged commit 2a88c7a into master Mar 23, 2018
@HyperBrain HyperBrain deleted the fix-local-invoke-watch branch March 23, 2018 10:33
jamesmbourne pushed a commit to jamesmbourne/serverless-webpack that referenced this pull request Oct 15, 2019
…ocal-invoke-watch

Purge handler module from require cache on watch
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

invoke local --watch is not working
1 participant