From e5e8d40cc8bf245d6f7a58a6103f3635af7ccb2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Thu, 18 Jun 2026 10:41:33 -0400 Subject: [PATCH] chore(producer): shim __filename/__dirname in the CJS banner Bundled CJS deps like wawoff2 call __dirname; without the shim they throw "__dirname is not defined in ES module" at render time. Also ignore .zed/. --- .gitignore | 3 +++ packages/producer/build.mjs | 18 +++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 33c7fe236d..77f369bd90 100644 --- a/.gitignore +++ b/.gitignore @@ -144,3 +144,6 @@ hyperframes-bench/ tmp/ # Studio-generated preview thumbnails .thumbnails/ + +# Local editor settings +.zed/ diff --git a/packages/producer/build.mjs b/packages/producer/build.mjs index 22fceae09f..4965c45a33 100644 --- a/packages/producer/build.mjs +++ b/packages/producer/build.mjs @@ -15,12 +15,20 @@ mkdirSync("dist", { recursive: true }); const scriptDir = dirname(fileURLToPath(import.meta.url)); -// The banner provides a real `require` function via createRequire so that -// esbuild's CJS interop (__require) works correctly in ESM output. -// Without this, bundled CJS deps (recast, yauzl, etc.) that call -// require("fs") throw "Dynamic require of 'fs' is not supported". +// The banner provides a real `require` (via createRequire) plus the CJS-only +// `__filename`/`__dirname` globals so esbuild's CJS interop works in ESM output. +// Without `require`, bundled CJS deps (recast, yauzl, etc.) that call +// require("fs") throw "Dynamic require of 'fs' is not supported"; without the +// dirname shims, deps like wawoff2 throw "__dirname is not defined in ES module". const cjsBanner = { - js: "import { createRequire as __cjsRequire } from 'module'; const require = __cjsRequire(import.meta.url);", + js: [ + "import { createRequire as __cjsRequire } from 'module';", + "import { fileURLToPath as __cjsFileURLToPath } from 'url';", + "import { dirname as __cjsDirname } from 'path';", + "const require = __cjsRequire(import.meta.url);", + "const __filename = __cjsFileURLToPath(import.meta.url);", + "const __dirname = __cjsDirname(__filename);", + ].join(" "), }; const workspaceAliasPlugin = {