Skip to content

jorins/pnpm-pack-zip

Repository files navigation

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.

Installation

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

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]

Example

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-zip

Install any runtime dependencies of my-lambda.

pnpm install

Modify 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

Static date modified of the files inside the zip

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"
    ...
}

About

npm pack zip, improved

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 5