autobarrel

Simple tool for creating "barrel" files in TypeScript

Usage no npm install needed!

<script type="module">
  import autobarrel from 'https://cdn.skypack.dev/autobarrel';
</script>

README

autobarrel

Simple tool for creating "barrel" files in TypeScript

Caveats:

  • Has not been tested on Windows
  • Only meant for TypeScript, as TS will check that there are no conflicting exports
  • Assumes you do not export default or have specific exports in the index. If you need this, exclude and re-export from another module
  • Does not actually check files for the presence of export in ts files
    • Possibly in future scope, PRs welcome. In the meantime use the paths / exclude / ignored options

CLI Usage:

autobarrel [--config path/to/autobarrel.json] [--watch]

autobarrel.json:

{
  /**
   * Relative glob patterns we want to process
   */
  paths: string[]
  /**
   * Relative glob patterns we want to ignore entirely
   */
  ignore?: string[]
  /**
   * Relative glob patterns of files / directories we want to avoid re-exporting
   */
  exclude?: string[]
}

Programmatic Usage:

import { autobarrel, resolveAutobarrelConfig } from "autobarrel"

//
await autobarrel(
  // Converts relative paths to absolute paths for consistency
  await resolveAutobarrelConfig({
    path: path.join(__dirname, "testing", "autobarrel.json"),
  })
)

License

MIT