Skip to content

API ​

CLI ​

sh
barrelify [options]
barrel [options]

barrel and barrelify are the same command.

FlagTypeDefaultDescription
--cibooleantrue in CI, false otherwiseDon't write files. Print the barrels that are out of date, and exit with an error if there are any.
--dry-runbooleanfalseDon't write files. Print the barrels that would change.
--cwdstring.Directory to search for index files, recursively.
--ignorestring[]—Globs of index files to skip, relative to --cwd.
--helpPrint usage.
--versionPrint the installed version.

Pass --no-ci to write barrels in CI.

sh
barrelify --ci                       # fail if any barrel is out of date
barrelify --cwd ./src                # only barrels in ./src
barrelify --dry-run                  # list barrels that would change
barrelify --ignore '**/generated/**' # skip generated directories

barrelify(options?) ​

Rewrites every // AUTO-BARREL index file, like the CLI.

Barrelify is ESM only. From CommonJS, load it with a dynamic import: const { barrelify } = await import('barrelify');.

OptionTypeDefaultDescription
cwdstring | URLprocess.cwd()Directory to search for index files, recursively.
dryRunbooleanfalseCompute every barrel, but don't write any.
ignorestring[][]Globs of index files to skip, relative to cwd.

Returns Promise<string[]>: the absolute paths of the barrels that changed, or would change with dryRun.

ts
import { 
barrelify
} from 'barrelify';
const
changed
= await
barrelify
({
cwd
: './src',
ignore
: ['**/generated/**'] });
const changed: string[]

There is no ci option. To check barrels from code, use dryRun and fail when anything would change:

ts
import { 
barrelify
} from 'barrelify';
const
stale
= await
barrelify
({
dryRun
: true });
if (
stale
.
length
> 0) {
throw new
Error
(`Barrels out of date:\n${
stale
.
join
('\n')}`);
}