Repository navigation
fix(cli): preserve caption arrays during transcript reimport - #6185
Conversation
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
jrusso1020
left a comment
There was a problem hiding this comment.
Approving at 6ac43580. This fixes a real bug that is still on main, and the tests prove it.
What I verified:
- On main,
patchCaptionHtmlfinds the array with a lazy\[[\s\S]*?\];regex, so an old caption word likeitems[i];ends the match early and the rewrite leaves a broken script behind. #6181 is still open and no other PR targets it. - I applied the PR onto current main:
normalize.test.tspasses 81 of 81. With onlynormalize.tsreverted, both new cases fail, so they guard the fix. - The new
findCaptionArraystill requires theconst <name> = [prefix and a closing;, the same shape the old regex accepted, so nothing that patched before is skipped now. A file that fails to parse is left untouched, which is the safe direction. - Both callers (
hyperframes transcribe <file> --dirthroughimportTranscript, andinit) go through this one function. The doc line matches that path. - Dependency:
acorn@^8.17.0is already inbun.lockwith the same integrity hash and is used by lint, parsers, core and studio. No new package gets resolved.
One non-blocking note on reuse. Studio's extractTranscript in packages/studio/src/captions/parser.ts already does exactly this boundary search (Acorn parseExpressionAt, then check the next token is ;). Now the read side and the write side each carry a copy. Moving the boundary finder into @hyperframes/parsers, which both packages already depend on, would keep them from drifting. Studio also accepts let/var and flexible spacing, and the CLI does not. That was true before this PR too, so it is fine as a follow-up.
Need: yes, a reimport can corrupt caption HTML today · Size: ok · Reuse: same logic as Studio's extractTranscript, could share via parsers (follow-up) · Simpler: already minimal
— Rames
What
Reimporting captions into an existing project now replaces the full transcript when an old caption contains
];, such asitems[i];. The CLI could report success while leaving invalid JavaScript in the caption HTML.const TRANSCRIPTwith old textitems[i];const scriptwith the same textWhy
The lazy array regex treats characters inside a word string as the array terminator.
Related work
Fixes #6181. #3852 / #3896 address Studio's read-side parser; #5226 addresses CLI script escaping. This fixes the remaining CLI rewrite boundary and retains those escaping rules.
How
Use Acorn to find the complete array expression and its semicolon. Acorn is already in the workspace lockfile and becomes a direct CLI dependency. The surrounding patch selection and script escaping stay in the existing code path.
Test plan
Independent GPT-6.1 Sol xhigh review: no blocker found. The reviewer independently passed all 145 normalizer/command tests and both real CLI reimports, including parser-boundary, escaping and dependency/lock checks..
Local workspace build/typecheck limitations: missing preinstalled inspector/AWS dependencies. Mintlify is unavailable. No dependency installation was performed. CI results are tracked on this PR.