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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@jsenv/file-size-impact

v14.3.37

Published

Add files size impact into pull requests

Downloads

1,800

Readme

File Size Impact

npm package

@jsenv/file-size-impact analyzes a pull request's impact on file sizes and posts the results as a comment in your GitHub PR.

  • ✅ Catch size impacts before merging pull requests
  • 📦 Track compressed file sizes (gzip, brotli)
  • 📊 Create meaningful reports by grouping files
  • 🔄 Integrate with any CI/CD platform (GitHub Actions, Jenkins, etc.)

Quick Start

npm install --save-dev @jsenv/file-size-impact
  1. Create a file size tracking script
  2. Set up your CI workflow
  3. Get size impact comments on every PR!

Table of Contents

Pull Request Comment

Here's how the PR comments look with explanations:

legend of pull request comment

| Text | How to read it | | ------------------------------ | ----------------------------------------------------------------------------------------------------------------------------- | | "remaining files (+4.71%)" | There is a group of files named "remaining files" and pull request has an overall impact of +4.71% on these files. | | "21.6 kB (+4.11 kB / +23.55%)" | The size after merge is 21.6 kB. Pull request adds 4.11 kB representing an increase of 23.55% of the size before merge. | | "Unmodified (4)" | Sum of files in that group that are not impacted by the pull request. | | Total (5) | Sum of files in that group. |

Installation

Step 1: Create a file size report script

First, create a script that generates your file size report:

// file_size.mjs
import { generateFileSizeReport } from "@jsenv/file-size-impact";

export const fileSizeReport = await generateFileSizeReport({
  log: process.argv.includes("--log"),
  rootDirectoryUrl: new URL("./", import.meta.url),
  trackingConfig: {
    dist: {
      "./dist/**/*": true,
      "./dist/**/*.map": false,
    },
  },
});

Test it locally:

node ./file_size.mjs --log

Step 2: Create a report script

// report_file_size_impact.mjs
import {
  reportFileSizeImpactInGitHubPullRequest,
  readGitHubWorkflowEnv,
} from "@jsenv/file-size-impact";

await reportFileSizeImpactInGitHubPullRequest({
  ...readGitHubWorkflowEnv(),
  buildCommand: "npm run dist",
  fileSizeReportUrl: new URL("./file_size.mjs#fileSizeReport", import.meta.url),
});

GitHub Workflow

Create a GitHub Actions workflow file:

# .github/workflows/file_size_impact.yml
name: file size impact

on: pull_request

jobs:
  file_size_impact:
    runs-on: ubuntu-latest
    name: file size impact
    steps:
      - name: Setup git
        uses: actions/checkout@v3
      - name: Setup node
        uses: actions/setup-node@v3
        with:
          node-version: "18.3.0"
      - name: Setup npm
        run: npm install
      - name: Report file size impact
        run: node ./report_file_size_impact.mjs
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

That's it! Now your PRs will automatically get file size impact comments.

Other Tools

If you want to use another CI tool like Jenkins:

  1. Create a GitHub token with repo scope at https://github.com/settings/tokens/new
  2. Update your report script to provide environment variables:
// report_file_size_impact.mjs for Jenkins
import { reportFileSizeImpactInGitHubPullRequest } from "@jsenv/file-size-impact";

await reportFileSizeImpactInGitHubPullRequest({
  rootDirectoryUrl: process.env.WORKSPACE, // Jenkins workspace
  repositoryOwner: process.env.GITHUB_REPO_OWNER,
  repositoryName: process.env.GITHUB_REPO_NAME,
  pullRequestNumber: process.env.PULL_REQUEST_NUMBER,
  githubToken: process.env.GITHUB_TOKEN,
  buildCommand: "npm run dist",
  fileSizeReportUrl: new URL("./file_size.mjs#fileSizeReport", import.meta.url),
  runLink: {
    url: process.env.BUILD_URL,
    text: `${process.env.JOB_NAME}#${process.env.BUILD_ID}`,
  },
});
  1. Configure your CI job to execute the necessary git commands:
git init
git remote add origin $GITHUB_REPOSITORY_URL
git fetch --no-tags --prune origin $PULL_REQUEST_HEAD_REF
git checkout origin/$PULL_REQUEST_HEAD_REF
npm install
node ./report_file_size_impact.mjs

How it Works

The file size impact analysis follows these steps:

  1. Checkout pull request base branch
  2. Execute an install command (npm install by default)
  3. Run a build command (npm run-script build by default)
  4. Generate a baseline file size report
  5. Merge pull request into its base
  6. Rebuild files
  7. Generate a second file size report
  8. Analyze differences between the two reports
  9. Post or update a comment in the pull request

API Reference

generateFileSizeReport

Scans the filesystem to compute file sizes with optional transformations:

import {
  generateFileSizeReport,
  raw,
  gzip,
  brotli,
} from "@jsenv/file-size-impact";

const fileSizeReport = await generateFileSizeReport({
  rootDirectoryUrl: new URL("./", import.meta.url),
  trackingConfig: {
    "critical files": {
      "./dist/main.js": true,
      "./dist/main.css": true,
    },
    "remaining files": {
      "./dist/**/*.js": true,
      "./dist/**/*.css": true,
      "./dist/main.js": false, // Exclude files already in "critical files"
      "./dist/main.css": false, // Exclude files already in "critical files"
    },
  },
  transformations: { raw, gzip, brotli },
});

Options

  • rootDirectoryUrl: Project root directory (required)
  • trackingConfig: File groups to track (optional)
  • transformations: Size transformations, like compression (optional)
  • manifestConfig: Configuration for files with dynamic names (optional)

reportFileSizeImpactInGitHubPullRequest

Analyzes PR impact and posts a comment with results:

import { reportFileSizeImpactInGitHubPullRequest } from "@jsenv/file-size-impact";

await reportFileSizeImpactInGitHubPullRequest({
  logLevel: "info",
  rootDirectoryUrl: "file:///directory",
  githubToken: "xxx",
  repositoryOwner: "jsenv",
  repositoryName: "file-size-impact",
  pullRequestNumber: 10,
  installCommand: "npm install",
  buildCommand: "npm run build",