Support transient dependencies when bundling (whitelisting) node modules #186
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What did you implement:
If you add a node module to the whitelist of
node-externals
, the module is bundled and the module's dependencies are added to the externals of the compiled chunk.The current version of the plugin checks all externals against the production dependencies of the service, so the "new" externals are not found there and are missing in the deployed functions. The functions will crash with a missing modules exception.
This PR fixes the issue, and adds all transient dependencies to the functions in case a node module is bundled.
How did you implement it:
The packager now fetches the dependency tree of the service by using
npm ls
, tries to find the used module versions and adds them to the deployed module list.The existing handling for first level modules that are present in the package.json has not been changed, so for the existing uses nothing special should be expected.
I tested it thoroughly with a combination of bundling some node modules fetched from VCS (GIT) - this would be the most prominent use case.