
Security News
NIST Under Federal Audit for NVD Processing Backlog and Delays
As vulnerability data bottlenecks grow, the federal government is formally investigating NISTβs handling of the National Vulnerability Database.
Auto-generate barrel files for typescript.
Scans your directories for index.ts
files with the // AUTO-BARREL
comment at the start.
Then re-writes the files as a barrel of all other javascript files in the directory.
Respects CommonJS/ESM compatibilities. Always ignores .gitignore
-d and node_modules
files.
Barrel files should be checked into version control.
npm i barrelify --save-dev
Given file structure
/
βββ¬ cjs
β βββ package.json // { "type": "commonjs" }
β βββ cts.cts
β βββ ts.ts
β βββ esm.mts
β βββ index.ts // AUTO-BARREL
βββ¬ esm
β βββ package.json // { "type": "module" }
β βββ cts.cts
β βββ ts.ts
β βββ esm.mts
β βββ index.ts // AUTO-BARREL
βββ¬ ignore
βββ foo.ts
βββ index.ts // _not_ AUTO-BARREL
npx barrelify
will rewrite:
/cjs/index.ts:
// AUTO-BARREL
export * from './cts.cjs';
export * from './ts.js';
/esm/index.ts:
// AUTO-BARREL
export * from './cts.cjs';
export * from './ts.js';
export * from './esm.mjs';
Note that the // AUTO-BARREL
comment is preserved, so future npx barrelify
will continue to keep files in sync.
barrelify
is an ESM module. That means it must be import
ed. To load from a CJS module, use dynamic import const { barrelify } = await import('barrelify');
.
It is also available as a CLI.
npx barrel --help
to get started.
It is generally recommended to only include barrelify
as a dev/test dependency.
Make sure your index files are flagged with // AUTO-BARREL
as the very first characters in the file. It will not generate index files by itself.
npx barrel --ci
will execute a special "dry-run" version, that throws an error if any files are found out of sync. This can ensure barrel files are properly generated before checking into version control, or during CI tests.
Programmatic way to access barrelify
. Performs same actions as CLI.
string (default = process.cwd())
Directory to start search for index files. Defaults/resolves from process.cwd().
Recursively checks directories starting from this point.
boolean (default = false)
If true, will not actually perform file writes.
string[] (default = [])
Globs for index files that should be explicitly ignored.
FAQs
Auto-generate TS barrel files.
The npm package barrelify receives a total of 140 weekly downloads. As such, barrelify popularity was classified as not popular.
We found that barrelify demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Β It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Security News
As vulnerability data bottlenecks grow, the federal government is formally investigating NISTβs handling of the National Vulnerability Database.
Research
Security News
Socketβs Threat Research Team has uncovered 60 npm packages using post-install scripts to silently exfiltrate hostnames, IP addresses, DNS servers, and user directories to a Discord-controlled endpoint.
Security News
TypeScript Native Previews offers a 10x faster Go-based compiler, now available on npm for public testing with early editor and language support.