Skip to content

chore(producer): shim __filename/__dirname in the CJS banner#1553

Open
miguel-heygen wants to merge 2 commits into
mainfrom
chore/producer-esm-dirname-shim
Open

chore(producer): shim __filename/__dirname in the CJS banner#1553
miguel-heygen wants to merge 2 commits into
mainfrom
chore/producer-esm-dirname-shim

Conversation

@miguel-heygen

@miguel-heygen miguel-heygen commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

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 / __dirname globals (alongside the existing require shim), and gitignore local .zed/ editor settings.

Why

packages/producer is bundled to ESM, but several bundled CJS dependencies assume CommonJS globals. require was already shimmed; wawoff2 (WOFF2 font subsetting) additionally reads __dirname and throws __dirname is not defined in ES module at render time.

How

Build the banner from import.meta.url:

  • createRequire(import.meta.url)require
  • fileURLToPath(import.meta.url)__filename
  • dirname(__filename)__dirname

Test plan

  • bun run build (producer) succeeds
  • Manual render exercising font subsetting (wawoff2) no longer throws

miguel-heygen commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator Author

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved at e5e8d40c per Rames D Jusso + Via consolidated stack review. Tiny, mechanical CJS-banner shim for __filename / __dirname. No concerns.

@miguel-heygen miguel-heygen force-pushed the chore/producer-esm-dirname-shim branch from e5e8d40 to 5ce82a2 Compare June 19, 2026 19:52
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/.

@james-russo-rames-d-jusso james-russo-rames-d-jusso left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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), then fileURLToPath(import.meta.url) for __filename, then dirname(__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-level import or const with 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 — ' '.join works but is harder to scan when debugging produced output. Non-blocking.

What I didn't verify

  • Whether wawoff2's __dirname usage actually resolves to a path that contains the WOFF2 data files at runtime — __dirname will point at the producer's dist/, not into node_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 vanceingalls left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 contains createRequire(import.meta.url), fileURLToPath(import.meta.url), dirname(__filename). Imports are from 'module' / 'url' / 'path' (functionally identical to the node: 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants