New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

barrel-begone

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

barrel-begone

Barrel files are files that just re-export a bunch of things from other files. If you're using a bundler, bundlers usually apply treeshaking and dead code elimination algorithms to remove any unused code.

1.0.5
latest
npm
Version published
Weekly downloads
10
-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

Barrel Begone

Barrel files are files that just re-export a bunch of things from other files. If you're using a bundler, bundlers usually apply treeshaking and dead code elimination algorithms to remove any unused code.

In many environments however, like test runners, browsers, CDN environments or server side JavaScript runtimes, treeshaking does not get applied. This means that lots of modules get loaded unnecessarily, which can cause significant performance slowdowns. Additionally, not all types of imports and exports can effectively be treeshaken.

Barrel Begone will analyze your packages entrypoints, and analyze your code and warn for various different things:

  • The total amount of modules loaded by importing the entrypoint
  • Whether a file is a barrel or not
  • Whether export * is used, which leads to poor or no treeshaking
  • Whether import * is used, which leads to poor or no treeshaking
  • Whether an entrypoint leads to a barrel file somewhere down in your module graph

For more information, I recommend reading Speeding up the JavaScript ecosystem - The barrel file debacle.

Usage

npx barrel-begone

Configuration

Cli options

Command/optionTypeDescriptionExample
--cwdstringDefaults to process.cwd()--cwd "/Foo/bar"
--maxModuleGraphSizenumberThe max amount of modules allowed in the graph--maxModuleGraphSize 20
--amountOfExportsToConsiderModuleAsBarrelnumberThe amount of exports to consider a module as barrel file--amountOfExportsToConsiderModuleAsBarrel 10
--infobooleanEnable extra logging--info

Config file

my-project/barrel-begone.config.js:

export default {
  cwd: process.cwd(),
  maxModuleGraphSize: 20,
  amountOfExportsToConsiderModuleAsBarrel: 5,
  info: true,
  rollup: {
    plugins: [myPlugin()]
  }
}

Programmatic usage

The analyzer can also be imported via javascript and uses programmatically:

import { barrelBegone } from 'barrel-begone';

const diagnostics = await barrelBegone({
  cwd: process.cwd(),
  maxModuleGraphSize: 10,
  amountOfExportsToConsiderModuleAsBarrel: 3,
  info: true,
  rollup: {
    plugins: [myPlugin()]
  }
});

FAQs

Package last updated on 30 Jan 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts