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-BARRELRun 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.
Features
- Specifiers that resolve: Writes
./foo.js,./foo.cjsand./foo.mjs, never extensionless paths. A.tsxcomponent 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.mtsfile. 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 --cifails 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.