// Embed executable-stories-react's built assets (the report stylesheet and the // interactive island IIFE) into a generated TS module so the formatter can inline // them into the standalone HTML report. // // Why codegen instead of reading from node_modules at runtime: the CLI ships as a // bun-compiled single-file binary (`bun build --compile`). That binary has no // node_modules, so `require.resolve("executable-stories-react/...")` throws at // runtime ("Cannot find module ... from /$bunfs/root"). Embedding the assets at // build time bakes them into the bundle for BOTH the tsup library build and the // bun binary. Import attributes (`with { type: "text" }`) are not an option — tsup // strips them — so a plain generated `.ts` string module is the portable path. // // Reads the assets via the package's public export map, so react#build must have // run first (turbo's `^build` guarantees this for every formatters task). import { createRequire } from "node:module"; import { readFileSync, mkdirSync, writeFileSync } from "node:fs"; import { dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; const require = createRequire(import.meta.url); const here = dirname(fileURLToPath(import.meta.url)); const outFile = join(here, "..", "src", "generated", "react-assets.ts"); const css = readFileSync( require.resolve("executable-stories-react/tailwind.css"), "utf8", ); const island = readFileSync( require.resolve("executable-stories-react/report-island.js"), "utf8", ); const contents = `/* eslint-disable */ // AUTO-GENERATED by scripts/embed-react-assets.mjs — do not edit. // Regenerated on every build/type-check/test/compile from the built // executable-stories-react assets. export const reactReportCss = ${JSON.stringify(css)}; export const reactIslandScript = ${JSON.stringify(island)}; `; mkdirSync(dirname(outFile), { recursive: true }); writeFileSync(outFile, contents, "utf8");