Make the dist directory configurable

Set it with `dist_dir` in bunext.config.ts or `--dist-dir` on any CLI
command (precedence: --dist-dir > BUNEXT_DIST_DIR > dist_dir > .bunext).
setupDistDir() resolves it in the CLI's preAction hook and at the start
of bunextInit(), so custom servers get the config value too.

- Read dist-derived paths from grabDirNames() inside functions instead of
  at import time; a guard test enforces this.
- Derive the client asset URL prefix from the dist dir instead of
  hard-coding /.bunext.
- Make the dev watcher ignore rules and probe follow the dist dir.
- Validate the dir: inside the project root, outside src/, public/ and
  node_modules/, URL-safe characters only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-11-09 03:55:54 +01:00
co-authored by Claude Opus 5.5
parent 4d4a79a6dd
commit b410b92f9f
35 changed files with 601 additions and 80 deletions
@@ -1,10 +1,9 @@
import grabDirNames from "../../utils/grab-dir-names";
import grabBunextPublicUrlPath from "../../utils/grab-bunext-public-url-path";
import isDevelopment from "../../utils/is-development";
import path from "path";
import { rmSync, mkdirSync, writeFileSync } from "fs";
const { BUNEXT_VENDOR_DIR, BUNX_CWD_DIR } = grabDirNames();
const VENDOR_ENTRIES: Record<string, string> = {
react: `
import React from "react";
@@ -42,6 +41,8 @@ const VENDOR_ENTRIES: Record<string, string> = {
};
export default async function bunReactModulesBundler() {
const { BUNEXT_VENDOR_DIR } = grabDirNames();
const dev = isDevelopment();
rmSync(BUNEXT_VENDOR_DIR, { force: true, recursive: true });
@@ -72,7 +73,7 @@ export default async function bunReactModulesBundler() {
rmSync(tmpDir, { force: true, recursive: true });
const PUBLIC_ROOT = BUNEXT_VENDOR_DIR.replace(BUNX_CWD_DIR, "/.bunext");
const PUBLIC_ROOT = `${grabBunextPublicUrlPath()}/vendor`;
global.BUNEXT_REACT_IMPORTS_MAP = {
imports: {