Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Allows plugins compiled with a toolchain that needs a WASI libc (ex. .NET, Go) to be used, such as the Wasm build of dprint-plugin-roslyn. Before this, creating a formatter for one failed with
Import "wasi_snapshot_preview1": module is not an object or function.What's provided
wasi.tsis a port of the sandboxed subset of WASI preview 1 that the dprint CLI provides (dprint/dprint#1303), with the same behaviour:poll_oneoff.proc_exitthrows instead of exiting.Pointers from the plugin are bounds checked and fail with "bad address" rather than throwing.
Plugins that export
_initialize(WASI reactors) are initialized before use, and a plugin that only exports_startfails with the same error as the CLI.Capturing plugin output
createContext,createFromBuffer,createFromWasmModule, andcreateStreamingtake an optionalonOutputfunction, which is called with the text a plugin writes to stdout or stderr. This allows capturing or ignoring it. Without it, the text is written to stderr as before.Behaviour changes for existing plugins
Plugin output is now written with
process.stderr.writein both Node.js and Deno. It wasDeno.stderr.writeSyncin Deno andprocess.stderr.writeSyncin Node.js, which doesn't exist, so the output of a plugin was silently dropped in Node.js.The existing
env.fd_writeimport now shares the WASI implementation, so control characters other than a newline or tab in a plugin's output are replaced withU+FFFD. This stops a plugin from sending escape sequences to the terminal and matches the CLI.Host.createImportObjecttakes an optional module, which is used to find the unsupported WASI functions to define.Differences from the CLI
Atomics.wait. Where that isn't allowed (ex. the main thread of a browser), the poll returns right away as though the time elapsed._initializefor old versions of dprint-plugin-gofumpt that run it as their start function (dprint 0.61.0 no longer loads dprint-plugin-gofumpt dprint#1306). That isn't done here, so I'd expect those versions to fail, though I didn't try one.Other
deno.lock, which was stale.Testing
wasi_test.tsports the CLI's tests of these functions. They run againsttest/test_wasi.wasm, a small module that imports the WASI functions and exports a wrapper for each, built byscripts/build_test_wasm.ts.deno test -P: 29 pass.deno task build:npmpasses, which runs the same tests in Node.