mirror of
https://github.com/hanzoai/frames.git
synced 2026-09-24 00:08:03 +00:00
chore(producer): shim __filename/__dirname in the CJS banner (#1553)
* 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/. * chore(producer): use a template literal for the CJS banner (review nit)
This commit is contained in:
@@ -144,3 +144,6 @@ hyperframes-bench/
|
||||
tmp/
|
||||
# Studio-generated preview thumbnails
|
||||
.thumbnails/
|
||||
|
||||
# Local editor settings
|
||||
.zed/
|
||||
|
||||
@@ -15,12 +15,18 @@ 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);`,
|
||||
};
|
||||
|
||||
const workspaceAliasPlugin = {
|
||||
|
||||
Reference in New Issue
Block a user