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

bramblejs

v0.0.0

Published

Elegantly visualising bundle sizes over time.

Downloads

3

Readme

bramble

Elegantly visualising bundle sizes over time.

Bramble is a bundle analyser. It can be easily composed into your build pipeline. It maintains data about, and generates visualisations for your bundle.

Install

npm install bramble

Why

If you've ever wondered what your package's overall size looks like over time - or wanted to regression test based on thresholds or limits - Bramble will help you do just that.

Bramble (via source-trace) can work on your raw source even if it's VanillaJS, Stage-0 TC29 features, JSON, Flow, or TypeScript, and it will follow all dependencies down the tree using Node's module resolution algorithm. It will ignore all dependencies such as devDependencies and peerDependencies, and will only include what's listed each module's dependencies across the entire dependency graph.

Differences to size-limit

Bramble is similar to size-limit in that it can fail a build based on a limit, but that's really the only similarities it shares.

  • Bramble is build agnostic; run on any JS variant and module system.
  • It has a check function that can use a hard limit, but also allows you to specify a threshold that is used to compare it to the bundle size of the previous version.
  • It tracks your bundle size over time and provides a way to generate a graph to visualise it.

Bramble is actually complementary to size-limit. Bramble can identify size and regressions overtime where size-limit can tell you very specific information about your WebPack build.

Build integration

The recommended ways to setup bramble are as follows.

Before committing the bumped version

NPM provides a version hook that gets executed after bumping the version in the package.json and before that version is committed and tagged. This is the recommended place to update the bramble-lock.json file.

{
  "scripts": {
    "version": "bramble write && git add . --ignore-errors"
  }
}

The bramble write command updates the lockfile and you must call git add . to add the lockfile to the stage so NPM can commit and tag it. We must --ignore-errors because if git add doesn't add any files, it will exit with a non-zero status code preventing the push.

If you opt-out of using the version hook, it's up to you to ensure that your lockfile is updated and committed prior to publishing.

Before pushing

Not only does Bramble record the information for the version that's currently in the package.json, it will also record data for the "unreleased" version if the version specified in the package.json already exists on NPM. This is because most do nothing with the version after releasing until the next time they release.

We also don't want to overwrite any data that's been published. However, we don't care if we overwrite the unreleased data. This means changes made on a particular branch will accumulate until released.

To set up a prepush hook, you can use something like Husky. If using Husky, you can simply add a prepush script.

{
  "scripts": {
    "prepush": "bramble write && git add . && git commit --allow-empty -am 'Update bramble-lock.json.'"
  }
}

This is much like the version hook except that you must commit the resulting change otherwise it will only be staged and you'd have to manually do this. We have to --allow-empty errors here because git commit will exit with a non-zero status if there is nothing to commit.

What about on pre-commit?

You could run this on precommit (via Husky, like prepush) in the same way the version hook is run, however, you might find that if you're committing a lot that it gets a bit annoying to have to wait for the file to be updated. If you do want to do this, just create a precommit script that does the same thing as version.

{
  "script": {
    "precommit": "bramble write && git add . --ignore-errors"
  }
}

Since this is just before committing, the git add . bit will ensure the files are added to the commit.

Netlify

This means that you can analyse bundles over time as part of PRs and releases.

  1. Configure Netlify to run bramble build (or an NPM script that does so)
  2. Point Netlify at the bramble/ folder (or whatever you passed to out-dir).

Regression testing

Since bramble tracks the state of your bundle sizes over time, you can run a check at build time to fail the build if your bundle doesn't meet a specific threshold.

For example, you can run this as part of your test step:

{
  "scripts": {
    "test": "webpack && bramble check --threshold 10k"
  }
}

JSON schema

The data is stored in a JSON schema inside the folder you configure for bramble called bramble-lock.json. Each entries in the dictionary represent a version and its corresponding data.

The current schema looks something like this.

{
  "0.1.0": {
    "date": "Thu, 28 Sep 2017 01:28:54 GMT",
    "size": 2048,
    "threshold": 1024
  },
  "1.0.0": {
    "date": "Thu, 28 Sep 2017 01:28:54 GMT",
    "size": 2048,
    "threshold": 1024
  },
  "unreleased": {
    "date": "Thu, 28 Sep 2017 01:28:54 GMT",
    "size": 2048,
    "threshold": 1024
  }
}

Update algorithm

When updating the bramble file it does the following:

  1. Get the current version.
  2. Get all versions from NPM.
  3. Check if the current version has been published. a. If it has, use "unreleased" as the current version instead. b. Continue using the current version.