Tim-B / grunt-aws-lambda

A grunt plugin to assist in developing functions for AWS Lambda.
MIT License
247 stars 100 forks source link

question: why do you need bundledDependencies ? #31

Closed hatimkhan closed 8 years ago

hatimkhan commented 9 years ago

I am looking at the source code for the packaging task. It uses npm.commands.install, but when I read the purpose of bundledDependencies in https://docs.npmjs.com/files/package.json, it seems it is for when we publish a module and not when installing a module.

Tim-B commented 9 years ago

The bundledDependencies is used to control what's included in the zip uploaded to AWS. For example, you wouldn't want to bundle grunt-aws-lambda in your zip because it's not actually used by your function when it runs in Lambda.

hatimkhan commented 9 years ago

That would go to the devDependencies section. I am looking at lambda_package.js and I see a call to npm.commands.install(). As far as I can tell, it does not care about the bundledDependencies. The install command is going to look at the 'dependencies' section and install all the dependencies in that section.

The bundledDependencies make sense when we are publishing a module and wanting to include certain dependencies in the published module. Since npm.commands.publish() is not being used, why do we need the bundledDependencies?

In fact, I completely removed the bundledDependencies from my package.json and after generating the zip file using the lambda_package, the zipped file included everything that I specified in the 'dependencies' section, which is what I expected. I am using npm v 2.11.2.

hatimkhan commented 9 years ago

It is ironic that the documentation for this project explicitly mentions that you must use bundledDependencies, when in fact it is not relevant. I lost confidence in this project and I ended up writing my own tasks. Thank you anyway for the inspiration and for sharing. I hope you either correct the documentation, or show me where the bundledDependencies are utilized. Like I mentioned in my previous comment, I completely removed the 'bundledDependencies' section and it had zero impact. npm v2.11.2, node v0.12.5, mac os x 10.10.5

Tim-B commented 9 years ago

I'll have to look into it, but I'm travelling at the moment so I haven't had a chance so far.

I don't remember the exact circumstances requiring it, but I suspect it's required if you include a dependency which you have installed globally. If that's the case then it would make sense to include all your dependencies there (even if you don't have them installed globally) so that your configuration works on any machine regardless of what is installed globally.

It would be great if you could check that scenario for me, otherwise I'll try and get a better answer for you as soon as I get a chance ;)

thedevkit commented 8 years ago

+1

My "dependencies" and "bundledDependencies" are always the same, and I can't see a scenario in which they would drift. As @hatimkhan mentioned, "devDependencies" would be where you include dependencies that you don't want to be deployed to lambda.

zoellner commented 8 years ago

I also do not see a difference when adding bundledDependencies. But I would like to have an option to only include those explicitly mentioned. My lambda function is part of a bigger project that includes packages like express etc. that aren't needed for the lambda function. Currently I have no way of excluding them from the zip archive

flyingsky commented 8 years ago

+1 it's not necessary to have bundledDependencies, just use dependencies.

Tim-B commented 8 years ago

The docs and tests related to bundledDependencies will be removed in the next version.

Thanks for the input!