ethical-utility-babel-directory-transpiler

raw JSON →
0.0.0 verified Fri May 01 auth: no javascript

A utility for transpiling entire directories with Babel, part of the Ethical web framework. Currently at version 0.0.0 and still in pre-release. It provides a simple API to transpile all files in a directory using Babel configuration, handling recursive directory traversal and output mirroring. Different from standalone Babel CLI in that it's designed as a programmatic utility within the Ethical ecosystem, with promise-based API and tight integration with Ethical's file system utilities.

error Error: Cannot find module '@babel/core'
cause Babel peer dependency not installed
fix
npm install @babel/core
error TypeError: transpileDirectory is not a function
cause Default import used instead of named import
fix
Use import { transpileDirectory } from 'ethical-utility-babel-directory-transpiler'
error Error: Unexpected token: punc (.)
cause Babel preset/plugin not compatible with source code
fix
Add required presets/plugins, e.g., @babel/preset-env for modern JS
error Error: ENOENT: no such file or directory, scandir './src'
cause Source directory does not exist
fix
Ensure the source directory exists before calling transpileDirectory
gotcha The package is in pre-release (v0.0.0); API may change without notice.
fix Pin to exact version and test upgrades carefully.
breaking Babel 6 and 7 presets/plugins are incompatible; ensure you pass options compatible with your installed Babel version.
fix Use @babel/preset-env for Babel 7, or babel-preset-env for Babel 6.
gotcha The 'extensions' option defaults to ['.js']; if you use TypeScript, you must explicitly include '.ts'.
fix Set extensions: ['.js', '.ts'] when transpiling TypeScript files (but note Babel will strip types only if preset-typescript is used).
deprecated The 'babelOptions' configuration may be renamed in future versions; currently undocumented.
fix Monitor the repository for updates.
gotcha Output directory is not cleaned before transpilation; files from previous runs remain.
fix Manually remove or clean the output directory before each build.
npm install ethical-utility-babel-directory-transpiler
yarn add ethical-utility-babel-directory-transpiler
pnpm add ethical-utility-babel-directory-transpiler

Shows how to transpile all JavaScript files from a source directory to an output directory with Babel presets and plugins.

import { transpileDirectory } from 'ethical-utility-babel-directory-transpiler';

async function build() {
  try {
    const result = await transpileDirectory({
      source: './src',
      output: './dist',
      babelOptions: {
        presets: ['@babel/preset-env'],
        plugins: ['@babel/plugin-transform-arrow-functions']
      },
      extensions: ['.js', '.jsx'],
      verbose: false
    });
    console.log(`Transpiled ${result.count} files`);
  } catch (error) {
    console.error('Transpilation failed:', error);
  }
}

build();