Companion v1.js is approaching 1500 lines — consider a split or bundler step

Open
#16 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
18/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Quiet
Tech stack
javascript
Domain
build-system

Research direction

The file in question is apps/api/src/companion/v1.js, which is an IIFE with section banners for anchors, Mermaid detection and Mermaid rendering. Start by finding where the build or serve step reads that file, since the two options are concatenation at serve time or an esbuild bundle. The issue asks for a decision first, so a newcomer should raise the choice with maintainers before splitting any code. Done means the chosen approach is agreed and the companion still runs unchanged in the sandboxed iframe.

Written by the indexing model from the issue text.

Description

triage

Surfaced by: code review on #15 (Mermaid auto-rendering).

After landing Mermaid rendering, apps/api/src/companion/v1.js is at ~1500 lines. Still readable thanks to the section banners (── Anchor rendering ──, ── Mermaid detection ──, ── Mermaid rendering ──), but the next feature on the companion at this scale would push it into "hard to hold in context" territory.

The companion is plain ES2020 in an IIFE (no imports, no bundler) — intentional, because it runs in a sandboxed opaque-origin iframe and we want to keep the build surface minimal. Two reasonable paths if this becomes painful:

  1. Concatenation at serve time — keep authoring split across multiple .js files in apps/api/src/companion/ (e.g., anchors.js, mermaid.js, protocol.js), concatenate at build into a single v1.js. No runtime change for artifacts.
  2. Adopt an explicit bundler step (esbuild, already a build-time dep) — author as ES modules, output a single IIFE.

Not urgent — file at this size is still maintainable. Open this when the third "I added 200 lines to v1.js" PR appears.

Dominant language
TypeScript
Stars
2
Forks
1
Avg merge
13h 38m
Merged PRs (30d)
24

Getting set up

  • Ships a Dockerfile or Docker Compose file
  • No pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from 0xPolygon/primer

All issues in 0xPolygon/primer

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.