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

barrelly

v1.2.0

Published

Create barrel files faster than Donkey Kong can throw them!

Downloads

23

Readme

barrelly

NPM license NPM version NPM downloads

Create barrel files faster than Donkey Kong can throw them!

With barrelly, you can automatically generate barrel files for your whole project in under a second!

Installation

pnpm i -D barrelly

Usage

Using barrelly on this project (1.2.0):

barrelly ./src

Will print:

┌─────────┬───────────────┬─────────┬──────┐
│  action │ folder        │ exports │ size │
├─────────┼───────────────┼─────────┼──────┤
│ updated │ tasks         │       6 │ 352b │
│ updated │ utils/fs      │       6 │ 350b │
│ updated │ utils         │       4 │ 332b │
│ updated │ classes       │       9 │ 315b │
│ updated │ utils/git     │       4 │ 246b │
│ updated │ utils/guards  │       4 │ 234b │
│ updated │ utils/string  │       3 │ 177b │
│ updated │ utils/path    │       2 │ 110b │
│ updated │ structures    │       2 │  64b │
│ updated │ types         │      25 │  53b │
│ updated │ utils/process │       1 │  47b │
└─────────┴───────────────┴─────────┴──────┘

Finished creating barrel files for 66 exports after 26ms!

Barrelly can map any kind of files as long as they follow the ESM import-export syntax. (.ts, .js, .jsx, .tsx, ...)

For JS

barrelly ./src -g .js

For TSX

barrelly ./src -g .tsx -a .tsx

What are barrel files?

Barrel files are a controversial topic when it comes to JavaScript development. They are basically files that export all the files in their folder as a bundle. They are always created as index.ts or index.js files because bundlers optimize away this path.

Barrel files have the advantage that:

  • You can ensure that everything you want to export is actually exported. This is particularly important for libraries and toolkits.
  • the number of lines of code can be reduced by bundling different imports from the same folder.

Reducing code:

import A from './letters/A'
import B from './letters/B'
import C from './letters/C'

to:

import { A, B, C } from './letters'
// import from the index file of the "letters" folder, but because of bundlers, the file part of the path is omitted.

Nevertheless, barrel files have a big problem, namely that you can import too much, which causes circular dependencies, which can cause test suites to crash, reduce performance and have other side effects. This is because this bundled export imports everything from the barrel file, but destructures the imports that you actually use. This destructuring process causes everything to be loaded at once, but most of it is discarded. If a bundler is used, this is largely irrelevant as everything is bundled into one file anyway.

Options

aliases (-a)

  • List of aliases handles by the bundler
  • Those extensions will be omitted inside the barrel file.
  • Default: []

exportEverything (-e)

  • Flag indicating whether everything should be exported from the target folder.
  • Necessary for libraries to ensure everything that should be exported will be exported.
  • Useful for sub folders to reduce the lines of code (LOC) when importing the code.
  • Default: false

ignore (-e)

  • Array holding all folders to ignore
  • If root is ignored, it ends prematurely
  • If everything is ignored, it ends prematurely
  • Default: []

glob (-g)

  • Glob describing all the file extensions to search for.
  • Default: .ts

path (target)

  • The path of the target folder, which acts as the root folder for the barrel file tree.
  • Default: ./src

semi (-s)

  • Style option indicating whether the barrel files should write semicolons (;) after each line or not.
  • Default: false

Use barrelly -h for CLI-specific options