chore(producer): shim __filename/__dirname in the CJS banner#1553
chore(producer): shim __filename/__dirname in the CJS banner#1553miguel-heygen wants to merge 2 commits into
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
99da598 to
e5e8d40
Compare
jrusso1020
left a comment
There was a problem hiding this comment.
Approved at e5e8d40c per Rames D Jusso + Via consolidated stack review. Tiny, mechanical CJS-banner shim for __filename / __dirname. No concerns.
e5e8d40 to
5ce82a2
Compare
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/.
5ce82a2 to
cd4308b
Compare
james-russo-rames-d-jusso
left a comment
There was a problem hiding this comment.
Reviewed at cd4308b0. ✅ Stamp-ready.
Mechanical CJS-banner extension: adds __filename + __dirname shims via fileURLToPath(import.meta.url) / dirname(__filename) alongside the existing createRequire. Test plan calls out wawoff2 as the concrete consumer; rationale matches the symptom verbatim (__dirname is not defined in ES module).
Verified
packages/producer/build.mjs:18-30— shim construction is sound:createRequire(import.meta.url), thenfileURLToPath(import.meta.url)for__filename, thendirname(__filename)for__dirname. No race / no async / executes once at module init. The 6-line banner is concatenated with single spaces — valid JS, each statement is a top-levelimportorconstwith terminating;..gitignore—.zed/addition is uncontroversial.- Bundle-output verification: I don't have eyes on the produced
dist/bundle, but the banner construction is a literal.join(' ')of well-formed statements; there's no codepath where this can produce invalid output.
Concerns
None.
Nits
- (nit) Banner could be a template literal (
'\n'.join) for readability —' '.joinworks but is harder to scan when debugging produced output. Non-blocking.
What I didn't verify
- Whether
wawoff2's__dirnameusage actually resolves to a path that contains the WOFF2 data files at runtime —__dirnamewill point at the producer'sdist/, not intonode_modules/wawoff2/. If wawoff2 reads relative paths from its module location, this shim won't help; if it just needs a defined string (e.g. for a Worker URL), it will. The test plan says "manual render exercising font subsetting no longer throws," which implies the second case holds — but I'd want CI coverage on this before relying on it long-term.
— Rames D Jusso
vanceingalls
left a comment
There was a problem hiding this comment.
Reviewed at cd4308b0. Concur with @james-russo-rames-d-jusso's R1 — banner shim is canonical and the construction is sound.
Verified at HEAD:
packages/producer/build.mjs:18-30— banner containscreateRequire(import.meta.url),fileURLToPath(import.meta.url),dirname(__filename). Imports arefrom 'module' / 'url' / 'path'(functionally identical to thenode:prefix style; consistent with existing producer code)..gitignore—.zed/addition is scoped + clean.
Trivial chore; nothing to flag under the band-aid bar. Rubber-stamp LGTM.
Review by Via

Stack: foundation of the GSAP keyframe + motion-path editing feature (#1553 → #1561).
What
Extend the producer's ESM-output build banner to define the CJS-only
__filename/__dirnameglobals (alongside the existingrequireshim), and gitignore local.zed/editor settings.Why
packages/produceris bundled to ESM, but several bundled CJS dependencies assume CommonJS globals.requirewas already shimmed;wawoff2(WOFF2 font subsetting) additionally reads__dirnameand throws__dirname is not defined in ES moduleat render time.How
Build the banner from
import.meta.url:createRequire(import.meta.url)→requirefileURLToPath(import.meta.url)→__filenamedirname(__filename)→__dirnameTest plan
bun run build(producer) succeeds