Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/bundler.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ A bundler plugin and specific instructions are available for the following bundl

- [esbuild](./bundlers/esbuild.md)
- [rolldown](./bundlers/rolldown.md)
- [tsup](./bundlers/tsup.md)

If your bundler is not listed here, please refer to the general guidelines below and consider reaching out to us for assistance.

Expand Down
37 changes: 37 additions & 0 deletions docs/bundlers/tsup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Installing Zen in a Node.js Application Bundled with tsup

Note: Zen runs only on the server side, it does not run in the browser.

Note: If `bundle` is set to `false` in the tsup configuration, Zen will work without any additional configuration.
For some general information about using Zen with bundlers, please refer to the [general bundler documentation](./bundler.md).

## Using the Zen esbuild Plugin

To use Zen with tsup, you need to install the `@aikidosec/firewall` package and add the Zen esbuild plugin to your bundler configuration like in the example below.

```js
import { cp, mkdir, writeFile } from "node:fs/promises";
import { defineConfig } from "tsup";
import { zenEsbuildPlugin } from "@aikidosec/firewall/bundler";

export default defineConfig({
entry: ["src/app.ts"],
bundle: true,
platform: "node",
format: "cjs", // or "esm"
outDir: "dist",
esbuildPlugins: [zenEsbuildPlugin()], // <-- Add the Zen esbuild plugin here
});
```

If you are using `cjs` as output format, add the following at the top of your application entry point, above any other imports, including Zen imports:

```js
require("@aikidosec/firewall/instrument");
```

Setting an explicit output directory and build format is mandatory for the plugin to work correctly.
After configuring tsup with the Zen plugin, you can build your application like done before.
However, **you need to ensure that the full output directory is deployed to your production environment.**

If your output format is set to `esm`, please also follow the instructions in the [ESM documentation](../esm.md) and modify your start command accordingly.
Loading