Skip to content

Barrelify ​

Generate and CI-verify TypeScript barrel (index.ts) files, with import extensions that resolve under Node ESM and TypeScript's nodenext.

Start an index.ts with // AUTO-BARREL:

ts
// AUTO-BARREL

Run npx barrelify, and it re-exports every sibling file:

ts
// AUTO-BARREL

export * from './button.js';
export * from './legacy.cjs';
export * from './theme.mjs';

Commit the result, and run barrelify --ci in CI to fail when a barrel is out of date.

Get started →

Features ​

  • Specifiers that resolve: Writes ./foo.js, ./foo.cjs and ./foo.mjs, never extensionless paths. A .tsx component exports as ./Button.js, matching TypeScript's output.
  • ESM/CJS aware: Reads the nearest package.json "type", and only re-exports files the barrel can load. A CommonJS barrel never re-exports an .mts file. See Module systems.
  • Opt-in: Only rewrites index files that start with // AUTO-BARREL. It never creates files or touches hand-written barrels.
  • CI check: barrelify --ci fails when a committed barrel is stale, and is the default in CI.
  • Keeps type-only exports: A line changed to export type * stays type-only on later runs.

Compared to ​

barrelsby and ctix generate barrels across a directory tree from configuration. Barrelify has no configuration: one marker per file opts it in, and each barrel only covers its own directory, plus its subdirectories' index files when asked.