npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

serverless-prune-path

v1.0.8

Published

A Serverless Framework plugin designed to manage and optimize the file paths included in deployment packages. It allows users to specify which paths should be kept or removed, offering granular control over the package's contents, which can result in smal

Downloads

13

Readme

Serverless Prune Path

Coverage Status

This Serverless plugin allows you to optimize your AWS Lambda package before deployment by providing the ability to selectively prune your package. You can either specify paths to keep or paths to delete within the given directory.

The plugin works by first unpacking the Lambda package, pruning paths according to your specification, and then repackaging. This gives you greater control over your deployment package, especially when you are using custom packages or other packaging plugins.

This can be particularly useful when your project has dependencies or files that are not needed in the production environment, allowing you to reduce the size of your deployment package and ultimately the cold start time of your Lambda functions.

Prerequisites

Before using the serverless-prune-path plugin, make sure you have an existing Serverless project set up and Serverless Framework installed.

If you don't have the Serverless Framework installed, you can do so by running:

npm install -g serverless

For more details on setting up a Serverless project and installing the Serverless Framework, please refer to the Serverless Framework Getting Started Guide.

How to Use

Installation

Install the plugin via npm:

npm install --save-dev serverless-prune-path

Configuration

In your serverless.yml, add the plugin and configure your prunePath settings in the custom field:

plugins:
  - serverless-prune-path

custom:
  prunePath:
    pathsToKeep:
      all:
        - 'path/to/keep/1'
        - 'path/to/keep/2'
    pathsToDelete:
      all:
        - 'path/to/delete/1'
        - 'path/to/delete/2'

The pathsToKeep and pathsToDelete configuration options accept an object with a special keyword all. When you use 'all' as a key, it means that the array of paths you specify will apply to every single function in your service.

In this version, only the 'all' configuration is available for specifying the scope of pruning. That is, all the Lambda functions are targeted for pruning with the specified paths. Pruning individual functions is a feature planned for a future release.

Example

custom:
  prunePath:
    pathsToKeep:
      all:
        - 'node_modules'
        - 'handler.js'

In this example, 'node_modules' and 'handler.js' will be the only paths kept in every function's package. All other files and directories will be removed from the packages.

Likewise, if 'all' is used under pathsToDelete, the specified paths will be deleted from all function packages.

custom:
  prunePath:
    pathsToDelete:
      all:
        - 'node_modules/aws-sdk'

In this example, 'node_modules/aws-sdk' will be deleted from every function's package.

Please note: Incorrect configuration may lead to the deletion of necessary files, causing your Lambda function to fail.

Prune Test

If you want to check the result of prune path, run the below command and check the packed lambda.

serverless package

If you are happy with the result, and want to deploy

serverless deploy

Future Work

We're always working to improve Serverless Prune Path and have some exciting features planned for the next version:

  • Individual Function Pruning: We plan to introduce a feature to allow pruning paths for individual functions, giving you even greater control over your lambda packages.

README in Other Languages