# tsdown

Build every library with a tsdown or tsup config, with the bundle cached.

The tsdown plugin gives every library with a tsdown or tsup config a `build` task, so a repository of libraries builds each one, in dependency order, from the cache when nothing changed.

## Add it

```sh
axle add tsdown
```

This writes it into the root `axle.toml`:

```toml
[plugins.tsdown]
source = "npm:@axle-rs/plugin-tsdown@0.1.0"
hash = "sha256-…"
```

## Tasks

A package or project with a `tsdown.config` or `tsup.config` file, `.ts` or another config extension, in its folder gets:

| Task    | Command             | Settings                                  |
| ------- | ------------------- | ----------------------------------------- |
| `build` | `tsdown`, or `tsup` | `outputs` the `outDir`, `dist` by default |

A package with both configs is built with tsdown.

Each command runs through the repository's package manager, such as `pnpm exec tsdown`, so it uses the version the package installs.

The output folder is read from the config without running it. When `outDir` is set to something other than a plain string, or to a folder outside the repository, the plugin leaves `outputs` out and Axle [finds the outputs](https://axlers.dev/docs/reference/cache.md#outputs) the build writes itself.

## Scripts the repository already has

A package's own script wins. When its `package.json` has a script with a task's name that runs something else, such as `"build": "tsdown && node scripts/copy.js"`, the plugin leaves that task alone and Axle runs the script. A script that runs the same command is replaced by the plugin's task, which runs it and adds its settings. The repository's `axle.toml` changes a task as it would any other, and wins over the plugin.

## Settings

| Setting | Default   | Meaning                                                |
| ------- | --------- | ------------------------------------------------------ |
| `build` | `"build"` | the name of the build task, or `false` to leave it out |

The plugin's answers are kept until a `tsdown.config.*` or `tsup.config.*`, a `package.json`, `pnpm-workspace.yaml` or a lockfile changes.
