I was surprised to see a headline last month about Deno being able to produce what I assume would be a single executable file.

This stayed in the back of my mind and then this week I thought maybe I'd try to go from absolutely no previous Deno knowledge experience to producing one of these files, as quickly as possible.

Here we go!

Installing Deno

Ok, so this should be pretty simple.

I already use asdf and there is an asdf plugin for Deno.

> asdf update; asdf plugin list all | grep deno
HEAD is now at c6145d0 Update version to 0.8.0
Updated asdf to release v0.8.0
deno                         *https://github.com/asdf-community/asdf-deno.git
> asdf plugin add deno
> asdf list all deno | tail -2
1.6.2
1.6.3
> asdf install deno 1.6.3
∗ Downloading and installing deno...
... 
The installation was successful!
> asdf global deno 1.6.3

Done.

Learning Just Enough To Produce A Binary

First thing is to look for recent Deno release notes to see what's there about this new executable binary feature.

Deno 1.6 Release Notes
Deno 1.6 adds the abilty to build your Deno projects into fully standalone, self-contained executables with `deno compile`. The release also introduces a built-in LSP for editor integrations, and experimental Apple Silicon support.

On the release page there is an example. Might as well try it?

> deno compile --unstable https://deno.land/[email protected]/http/file_server.ts
...
Download https://deno.land/[email protected]/bytes/mod.ts
Check https://deno.land/[email protected]/http/file_server.ts
Bundle https://deno.land/[email protected]/http/file_server.ts
Compile https://deno.land/[email protected]/http/file_server.ts
Emit file_server
> 

Looking closer at the executable, I see that it is about 48 mebibytes. (Yeah, I said "mebibytes", what?)

Ok, that's a pretty big file and I don't even know what all is in there. Let's see check out how to build off our own minimal project and see how much smaller the file is.

Deno "Hello, World"

Ok, so what if I try to replace that last part of the command line example with a simple file I write myself containing simply:

console.log("hello, world");

So then just cross my fingers and try it?

> deno compile --unstable hello.ts 
Check hello.ts
Bundle hello.ts
Compile hello.ts
Emit hello
> ./hello
hello, world
> ls -ks file_server hello
49516 file_server* 49416 hello*

It worked!

However it seemed to only reduce the size of the binary by 100 kibibytes (right?) so we're still talking about a file that is extremely large for what it does.

As a reference point, I quickly wrote the same "Hello, World" program in golang and it results in a 97.5% reduction in file size.

> cat hello.go
package main
func main() {
  println("hello, world")
}
> go build hello.go
> ls -ks hello
1180 hello*

Still, it's pretty cool that it's that fast and easy to build something that could be quickly be executed on another computer, after a 50 mebibyte download and a double click, right?