This tool will create an archive of your package similar to npm pack, but
will generate a zip file instead of a tarball.
It is designed to help you deploy npm packages to AWS Lambda or Azure Function Apps.
Although the project is named after pnpm and was created in order to support packaging of dependencies from pnpm workspace roots, it should work with npm and yarn as well.
This project uses the npm-packlist project to build up the list of files to include and all bundle dependencies. Check out their documentation on how to include and exclude files from the archive.
Project initially based on
npm-pack-zip, but most of the
codebase has been rewritten.
Package is hosted under @truesec on GitHub packages. You'll need to set up
access, see npm
documentation
``
pnpm install --save-dev @truesec/pnpm-pack-zip
Usage: cli.js [options...]
Boolean options can be negated by prefixing with "no-" e.g. "--no-add-version"
Options:
--help Show help [boolean]
--version Show version number [boolean]
-s, --source Path of the package to pack
[string] [default: current working directory]
-d, --destination Output path of the resulting .zip-archive
If directory, use default file name.
[string] [default: current working directory]
-l, --log-level Level of detail in logs
[choices: "none", "error", "warning", "info", "verbose", "debug"] [default:
"info"]
--add-version Add package version to output path
Ignored if destination is file
[boolean] [default: true]
--add-commit-hash Add latest git short hash to output path
Ignored if destination is file
[boolean] [default: false]
--static-date-modified Sets a static last modified date for all files in
archive [boolean] [default: false]
--add-root-node-modules Add files from pnpm workspace root's
node_modules.
Workaround for
https://github.com/pnpm/pnpm/issues/4834
[boolean] [default: false]
my-lambda is an npm package I want to run as an AWS Lambda Function.
Install pnpm-pack-zip locally in my-lambda
pnpm install --save-dev pnpm-pack-zipInstall any runtime dependencies of my-lambda.
pnpm installModify my-lambda/package.json:
"scripts": {
"package": "pnpm-pack-zip"
...
}
Create the .zip file containing my-lambda and its dependencies, ready to upload to AWS Lambda
pnpm run package
If you need to create *.zip package with static date modified of the files
inside then you can use the flag --static-date-modified . This can be used if
you are using automation deployment to the AWS, where the server checkouts the
code (brand new) each time deployment is triggered. Hash can be calculated so
that you can check with the hash in AWS so that you can check if the code is
changed.
"scripts": {
"package": "pnpm-pack-zip --static-date-modified"
...
}