Skip to content

fix d2js CJS asset paths - #2793

Merged
alixander merged 1 commit into
masterfrom
agent/fix-cjs-asset-path
Aug 3, 2026
Merged

fix d2js CJS asset paths#2793
alixander merged 1 commit into
masterfrom
agent/fix-cjs-asset-path

Conversation

@alixander

@alixander alixander commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • define the Node bundle asset directory at bundle runtime instead of allowing Bun to inline the source file URL
  • use the runtime directory for WASM, worker, and ELK assets in both ESM and CJS builds
  • mark the generated CJS output directory as CommonJS so Node can load the package through its require export
  • preserve browser behavior and package layout

Why

Bun 1.3.14 inlined import.meta.url in the CommonJS bundle as the source path. The CJS integration test then looked for wasm_exec.js outside d2js/js, blocking the stage-only npm workflow before it could test trusted publishing. A packed-package review also found that Node treated the generated CJS .js files as ESM because the root package uses type: module; the nested marker makes the declared require export work in Node.

Verification

  • git diff --check
  • formatted source verified by the Linux build
  • Linux Bun 1.3.14 run on the banner fix: 32 unit tests passed; CJS and ESM integration both passed
  • current Bun 1.3.14 local integration suite: 2 passed, 0 failed
  • packed @terrastruct/d2 tarball installed in an isolated directory; both CommonJS and ESM builds compiled x -> y under Node 24
  • packed tarball contains dist/node-cjs/package.json with the CommonJS marker
  • local macOS unit baseline was unchanged at 20 pass / 12 fail; the pre-patch build produced the same result

Nothing is published or staged by this PR.

@alixander
alixander force-pushed the agent/fix-cjs-asset-path branch from dc0057c to d899863 Compare August 3, 2026 01:27
@alixander
alixander force-pushed the agent/fix-cjs-asset-path branch from d899863 to a0a6e19 Compare August 3, 2026 01:30
@alixander
alixander marked this pull request as ready for review August 3, 2026 01:32
@alixander
alixander merged commit 4c637a0 into master Aug 3, 2026
2 of 6 checks passed
@alixander
alixander deleted the agent/fix-cjs-asset-path branch August 3, 2026 01:33
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.

1 participant