JSPM

@netlify/zip-it-and-ship-it

0.4.0-18
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 532202
  • Score
    100M100P100Q214848F
  • License MIT

Zip it and ship it

Package Exports

  • @netlify/zip-it-and-ship-it

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@netlify/zip-it-and-ship-it) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

zip-it-and-ship-it

npm version Coverage Status Build Dependencies Downloads

This module handles zipping up lambda functions with their dependencies before deployment. You are probably looking for netlify-cli or js-client.

Installation

npm install @netlify/zip-it-and-ship-it

Usage

const { zipFunctions } = require('@netlify/zip-it-and-ship-it')

zipFunctions('functions', 'functions-dist')

This will take all functions in the functions folder and create a matching .zip file in the functions-dist folder.

Each function can either be a single .js file that exports a handler or a folder with a .js with the same name as the folder exporting a handler.

The packaging tool will look for the package.json closest to the handler and use that for dependency resolution. Make sure you've run npm install or yarn for each package.json before using zip-it-and-ship-it.

Ie, the following combinations would all work:

/functions/foo.js
/package.json
/node_modules/
/functions/foo.js
/functions/bar/bar.js
/functions/package.json
/functions/node_modules/
/functions/foo.js
/functions/bar/bar.js
/functions/bar/package.json
/functions/bar/node_modules
/package.json
/node_modules/

Zip It and Ship It will only include dependencies in each zip file that's been required from the relevant handler file.

File Serving

As of v0.3.0 the serveFunctions capability has been extracted out to Netlify Dev.

API

promise(zipped) = zipFunctions(source, destination, [opts])

Discover and zip all functions found in the source path into the destination. Returns a promise containing a zipped array of function objects.

The array of zipped function objects has the following shape:

const zipped = [
  {
    path, // Absolute filepath to zipped function
    runtime // 'go' or 'js'
  }
  //...
]

opts include:

{
  parallelLimit: 5, // Limit the number of concurrent zipping operations at a time
  zipGo: false // Don't zip go functions, just move them to the destination path
}

CLI

A minimal CLI version of zip-it-and-ship-it is provided for use inside the build-image, although this is automatically invoked on users behalf during builds and you typically do not need to run this yourself.

$ zip-it-and-ship-it --help
@netlify/zip-it-and-ship-it: Zip lambda functions and their dependencies for deployment

Usage: zip-it-and-ship-it [source] [destination] {options}
    --zip-go              zip go binaries (default: false)
    --help, -h            show help
    --version, -v         print the version of the program

See Also

Check our official docs here.