Skip to content

fix: switch JS/WASM bindings from TinyGo to standard Go#50

Merged
reteps merged 2 commits intomainfrom
js-bindings-fix
Apr 6, 2026
Merged

fix: switch JS/WASM bindings from TinyGo to standard Go#50
reteps merged 2 commits intomainfrom
js-bindings-fix

Conversation

@reteps
Copy link
Copy Markdown
Owner

@reteps reteps commented Apr 6, 2026

Summary

  • Switches from TinyGo to standard Go (GOOS=js GOARCH=wasm) to fix JS bindings that panic on reflect.AssignableTo and \s regexp failures in the buildkit parser
  • Replaces encoding/json in our formatting code with a reflection-free []string JSON marshal/unmarshal (lib/json.go)
  • Simplifies JS bindings by using syscall/js instead of manual memory management (malloc/free/pointer arithmetic)
  • Adds wasm-opt to the build pipeline (7.6 MB → 6.9 MB)
  • Adds JS integration tests including the issue JS bindings are broken #25 reproduction case

Test plan

  • go test ./... — all Go tests pass
  • node --test dist/format.test.js — all 6 JS tests pass, including:
    • Shell-form CMD (the original JS bindings are broken #25 bug)
    • JSON-form CMD/RUN (also broken under TinyGo, previously unreported)
    • Indent and trailing newline options

Fixes #25

🤖 Generated with Claude Code

TinyGo's WASM target has two blocking bugs that break the JS bindings:
- reflect.AssignableTo panics with interfaces, breaking encoding/json
  used by both our code and the moby/buildkit parser (#4277)
- regexp \s (Perl character classes) fails in newer TinyGo versions,
  also breaking the buildkit parser

This commit:
- Switches from TinyGo to standard Go (GOOS=js GOARCH=wasm), which
  has full reflect and regexp support
- Replaces encoding/json usage in our code with a reflection-free
  []string JSON marshal/unmarshal (lib/json.go), avoiding HTML-escaping
  of <, >, & as a bonus
- Simplifies the JS bindings by using syscall/js instead of manual
  memory management (malloc/free/pointer arithmetic)
- Adds wasm-opt to the build pipeline to reduce binary size
- Adds JS integration tests covering the issue #25 reproduction case

Binary size increases from 2.0 MB to 6.9 MB (after wasm-opt), but the
bindings now actually work for all Dockerfile forms.

Fixes #25

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@reteps
Copy link
Copy Markdown
Owner Author

reteps commented Apr 6, 2026

Unfortunately, this blows up the binary size from 2->7 mb, but I can't control usage of JSON serialization in the buildkit parser.

Runs Go tests and JS build+tests on pull requests and pushes to main.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@reteps reteps merged commit 1f3076e into main Apr 6, 2026
3 checks passed
@reteps reteps deleted the js-bindings-fix branch April 6, 2026 03:52
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.

JS bindings are broken

1 participant