BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Deno Now Compiles to Self-Contained, Standalone Binaries

Deno Now Compiles to Self-Contained, Standalone Binaries

This item in japanese

Bookmarks

Deno 1.6 introduced the compilation of Deno projects into standalone executables, whose size Deno 1.7 further reduced (up to 60%). Deno now has a dedicated language server that seeks to improve the experience of Deno developers in code editors. Deno also added support for data URLs, enabling the execution of computer-generated code.

Deno 1.6’s release note explained the new compilation toolchain as follows:

deno compile does for Deno what nexe or pkg do for Node: create a standalone, self-contained binary from your JavaScript or TypeScript source code. This has been the single most upvoted issue on the Deno issue tracker.

Compiling Deno applications to self-contained binaries addresses the same use cases as Node or the Nectarjs JavaScript native compiler. Some developers for instance may want to make a closed-source commercial/demo/trial version of their application; deploy their application as a single file on a series of platforms; or incorporate assets inside the executable for portability purposes.

The release note provides an example of usage of the new compilation feature:

The Deno compiler can compile to any supported architecture (Windows x64, MacOS x64, and Linux x64) independently of the architecture used by the compiling computer. This means a Linux machine can create executables for Windows or MacOS. The --lite option (available in Deno 1.7) generates binaries that are 40-60% smaller. deno compile also creates binaries that have built-in CA certificates, custom V8 flags, locked-down Deno permissions, and pre-populated command line arguments. A few limitations apply, however. Deno compilation supports neither web workers nor dynamic imports.

Deno 1.6 introduced a new lsp subcommand that starts a language server implementing Language Server Protocol (LSP). LSP defines the protocol used between a code editor or integrated development environment and a language server to provide convenient features like code completion, go-to-definition, or linting. Currently, deno lsp implements code completion, hints on hover, go-to-definition, and go-to-references actions. The Deno VSCode extension does not yet support deno lsp.

Deno 1.7 adds support for data URLs. The following data URLs

data:application/typescript;base64,ZXhwb3J0IGNvbnN0IGEgPSAiYSI7CgpleHBvcnQgZW51bSBBIHsKICBBLAogIEIsCiAgQywKfQo=

encode in base64 the following TypeScript source code:

export  const a =  "a";

export  enum  A  {
  A,
  B,
  C,
}

The code encoded in the data URL can then be imported with the regular import syntax (import * as a from "data:application/typescript;base64,..."). The feature is particularly useful for executing dynamically-generated content. A similar feature is used to implement the interactive playground for the Svelte front-end framework. Source code entered in text areas by the user of the playground is preprocessed, bundled, imported through a URL object, executed, and displayed in the preview pane. Data URLs can also be used in web workers.

The release notes for Deno 1.6 and 1.7 detail additional minor features that are part of the release. Deno is open-source software available under the MIT license. Contributions are encouraged via the Deno Project and should follow the Deno contribution guideline.

Rate this Article

Adoption
Style

BT