Anyway to use deno fmt within a script itself without having to call deno again?
I am working on a code generator and I'd like to run a string through deno fmt before I save to file.
I've seen how to do it by calling deno to format the file, but wondering if I could do this within the script itself?
See this function here:
I'd like this string passed through deno fmt before saving, within the deno Script itself.
I then process that string content like this:
I dont want to allow Deno.Command, so was wondering if another way.
Thank you.
6 Replies
nope unfortunately there are issues on the deno repo about adding such functions (exposing deno cli to scripts) but it never gained any traction
Okay thank you!
This was the workaround i ended up with, no temp file and just fmt the whole directory
Im really not too familiar with this stuff
I find Deno great for prototyping ideas as its brilliant but not too familiar with internals etc, but does my logic sound correct on this?
Here is the rust code for fmt:
https://github.com/denoland/deno/blob/main/cli/tools/fmt.rs
I found this blog:
https://deno.com/blog/wasmbuild
maybe i could just try this with the deno cli code
i will have a look
GitHub
deno/cli/tools/fmt.rs at main ยท denoland/deno
A modern runtime for JavaScript and TypeScript. Contribute to denoland/deno development by creating an account on GitHub.
Deno Blog
wasmbuild - Using Rust in Deno and Web Apps
An easier way to build Rust for Deno and the Web.
Deno uses dprint internally which uses wasm plugins to format
Turns out the author already expose deno wasm wrapper
GitHub
GitHub - dprint/js-formatter: JS formatter for dprint Wasm plugins.
JS formatter for dprint Wasm plugins. Contribute to dprint/js-formatter development by creating an account on GitHub.
great thank you I will have a look at that! ๐