bndl_cli

Crates.iobndl_cli
lib.rsbndl_cli
version1.8.1
sourcesrc
created_at2023-11-15 16:10:34.332654
updated_at2024-10-02 08:51:02.05816
descriptionA basic TypeScript transpiling and bundling tool for (primarily backend) monorepos
homepagehttps://github.com/segersniels/bndl/
repositoryhttps://github.com/segersniels/bndl/
max_upload_size
id1036546
size109,437
Niels (segersniels)

documentation

README

bndl

crates.io npm GitHub Workflow Status (with event)

Introducing bndl, a barebones TypeScript transpiling and bundling tool for backend monorepos.

It aims to be a near drop-in replacement for those accustomed to tsc, utilizing the existing tsconfig.json in your project. bndl traverses the monorepo, builds the current workspace with SWC, identifies the dependencies used by the consumer, and copies them to the compiled directory's node_modules.

The result? An output directory containing everything necessary for your app to run. Simply copy the dist directory to a Docker image and execute it.

Installing

cargo

$ cargo install bndl_cli

npm

$ npm install -g bndl-cli

curl

$ sh -c "$(curl -fsSL https://raw.githubusercontent.com/segersniels/bndl/master/scripts/install.sh)"

wget

$ sh -c "$(wget https://raw.githubusercontent.com/segersniels/bndl/master/scripts/install.sh -O -)"

Usage

Usage: bndl [OPTIONS] [COMMAND]

Options:
  -p, --project <project>  The path to the project config file
      --outDir <outDir>    Specify an output folder for all emitted files.
      --clean              Clean the output folder if it exists before bundling
      --only-bundle        Skips compilation and only bundles the input files, assuming they are already compiled beforehand
      --no-bundle          Disable automatic bundling of internal monorepo dependencies
  -m, --minify             Minify the output bundle
  -w, --watch              Experimental: watch the input files for changes and recompile when they change
      --exec <exec>        Experimental: use in conjunction with --watch to execute a command after each successful compilation
  -h, --help               Print help
  -V, --version            Print version

Known limitations

Building dependencies

bndl only builds the current workspace, not its dependencies. You need to build internal dependencies before the consuming workspace. Using something like Turborepo, you can run npx turbo run build --filter <your-workspace> with a config like this:

{
    "tasks": {
        "build": {
            "dependsOn": ["^build"],
            "outputs": ["dist/**"]
        }
    }
}

This config ensures Turborepo builds internal dependencies first before the consuming workspace, making them ready for bundling.

Watch

bndl only watches the current workspace for changes, not internal dependencies. To handle this, use the --exec option to recompile and bundle internal dependencies.

bndl --watch --exec "npx turbo run build --filter <your-workspace>^... && npx bndl --only-bundle && npm run start"

This command will first build all internal dependencies (excluding the consuming application) and then tell bndl to bundle them. Note that this triggers only when a file changes in the consuming application. Save a file in the consuming application to trigger a rebuild.

Using Turborepo and its cache should make this relatively fast, minimizing delay between file changes and restarts.

Contributing

Expect missing functionality and potential breakage. This tool was created for a specific use case and might differ from your needs. Feel free to open issues or PRs to add the functionality you need.

Submit issues with panic logs or debug information (RUST_LOG=debug bndl ...) for quicker resolution.

Commit count: 227

cargo fmt