Skip to content

feat(fmt): prototype dprint-npm + in-process WASM backends for deno fmt#34682

Draft
bartlomieju wants to merge 1 commit into
mainfrom
feat/fmt-dprint-prototype
Draft

feat(fmt): prototype dprint-npm + in-process WASM backends for deno fmt#34682
bartlomieju wants to merge 1 commit into
mainfrom
feat/fmt-dprint-prototype

Conversation

@bartlomieju

Copy link
Copy Markdown
Member

Prototype exploring a different model for deno fmt: instead of compiling
the dprint formatter plugins into the binary as native Rust crates, drive
formatting through the pinned dprint npm package and its WASM plugins,
with a default version and plugin set pinned in the binary. This decouples
the formatters from the core binary so they can be versioned and updated
independently.

Everything is gated behind the DENO_FMT_DPRINT environment variable, so
the existing in-process formatter remains the default and is untouched. Two
backends are implemented for comparison. DENO_FMT_DPRINT=1 shells out to
the pinned dprint CLI npm package. DENO_FMT_DPRINT=wasm runs the dprint
WASM plugins in the same process by embedding a MainWorker (the same
pattern deno lint uses for its plugin host) and loading the plugins via
@dprint/formatter from pinned @dprint/* npm packages, so V8 executes the
WASM with no subprocess. Both backends reuse Deno's own file discovery and
map the full deno.json fmt option set onto generated dprint config, and
produce byte-identical output to the current formatter (SQL aside, which
uses a different underlying formatter).

A spec test under tests/specs/fmt/dprint_npm_parity runs the same
fmt --check across all three code paths via the variants matrix. Note
the two dprint variants fetch packages/plugins from the network and so are
not hermetic yet; vendoring the @dprint/* packages and g-plane plugin WASM
into the test registry would fix that. Draft, work in progress.

Behind the DENO_FMT_DPRINT env var, add two prototype backends for
`deno fmt` that use the pinned dprint npm package + WASM plugins instead
of the in-process dprint plugin crates:

- DENO_FMT_DPRINT=1 (cli): shell out to the pinned dprint CLI npm package.
- DENO_FMT_DPRINT=wasm: run the dprint WASM plugins in-process by embedding
  a MainWorker (like deno lint's plugin host) and loading the plugins via
  @dprint/formatter from pinned @dprint/* npm packages. No subprocess.

Both reuse Deno's file discovery and map the full deno.json fmt option set
onto generated dprint config. The default in-process formatter is unchanged.

Adds a spec test (tests/specs/fmt/dprint_npm_parity) that runs the same
`fmt --check` under all three backends via the variants matrix.
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