jacobdeichert/mask

Use deno for typescript and ts code blocks

brandonkal opened this issue · 2 comments

Deno is a secure TypeScript runtime written in rust.

I propose that typescript code blocks use Deno to execute.
It handles dependency fetching and compiling TypeScript to JavaScript automatically. This means a maskfile.md can be self contained, there is no need to run an npm install to make the JavaScript blocks function.

Because Deno requires permission flags to operate, there would need to be a way to provide permission arguments to the deno run invocation.

Brilliant... assigning ts/typescript lang code to deno definitely makes sense to me with the current state of things. I was wondering how to add deno support, and this solves it 👍

Regarding deno permission args, I'm open to suggestions. Perhaps the first line of the codeblock could define which args to pass.. as a comment to keep it simple.

## deno_cmd
~~~ts
// --allow-read --allow-write     etc...
console.log('this is denoooo');
~~~

Yes. Deno permissions are hard. For ref here is how you can do it with a shebang. It looks rather ugly because -S isn't supported well outside macOS.

One thing I've been doing with my deno files is adding file-level JSDoc comments for copyright, author, description. I then parse that to generate my README.md. I've considered adding denoargs in there but abandoned that idea as it is not JSDoc standard.

So you could have:

/** 
 * @author brandonkal
 * @donoargs --allow-read --allow-write
 */

That gets too repetitive though.

What I would suggest is this:

// run: [allow-read, allow-write]

That line would have to be within the top 5 lines of the code block. A string may be better than an array, but ideally it would also be parsable as YAML for other tools. With explicit allow reads etc it would need to handle multiple lines:

// run: >
//   --allow-read=/a/very/long------path/project/foo
//   --allow-write=/a/very/long------path/project/foo

console.log('this is denoooo')

When you need multiple lines though, array syntax is easier to manage to my eye.