nfriedly / node-bestzip

Provides a `bestzip` command that uses the system `zip` if avaliable, and a Node.js implimentation otherwise.
MIT License
81 stars 17 forks source link

Command line option to include dependencies specified in the package.json #27

Closed misterdev closed 5 years ago

misterdev commented 5 years ago

First of all thanks, this tool is really useful!

To automate an AWS lambda deployment I needed a programmatic way to create an archive containing all the runtime files needed to execute this function. There are some npm packages that can do this but are less configurable (pack-zip, npm-pack-zip)

Include dependencies

When you need to include your package.json dependencies from node_modules, you can use the --dependencies option to specify the location of your package.json file:

bestzip build.zip build/* --dependencies

will include all the modules listed inside "dependencies" in your ./package.json file.

Alternatively you can specify the relative path:

cd build/ && bestzip ../build.zip * -d ../package.json

nfriedly commented 5 years ago

Hi @misterdev, thanks! This is interesting, but I'm not sure that it makes sense to put it into the bestzip package. I'm trying to keep this module to be a fairly generic and minimal zip replacement.

What configuration do you need that other modules don't include? The npm pack command was made for that kind of situation, and I believe it follows the same configuration options that npm publish does, so it's fairly flexible.

If you specifically need a .zip instead of a .tar, it might make more sense to try and get your needed features integrated into pack-zip or npm-pack-zip. The later seems to be both actively maintained and follows the same configuration rules as npm pack (via npm-packlist).

If none of those options work for you, then I'd recommend making a new module that adds this feature and then calls bestzip under-the-hood.

Lastly, I think there's a bug in this PR somewhere, because a lot of the tests are failing on trying to zip the source file "undefined".

misterdev commented 5 years ago

Hi @nfriedly, thanks for your reply!

I need a solution that allows generating a .zip specifying multiple sources to include, but none of the above are what I'm looking for. I'll probably go for a new module as you suggested ;)

nfriedly commented 5 years ago

Have you ever used the package.json files property? It lets you specify a list of files/folders that will be included in publishing instead of the default behavior of "grab everything that isn't ignored".

No worries if that won't work for you, I just know that a lot of people aren't aware of it.

misterdev commented 5 years ago

Nice to know, I'll take a look at that, thanks! ;)