View Source README

DenoEx Logo

Easily run TypeScript and Javascript using Deno right from Elixir!

Hex.pm GitHub Workflow Status (master) Coveralls master branch Support the project


Contents

Introduction

DenoEx is designed to make it simple to run scripts using Deno from your Elixir applications. Deno is a modern runtime for JavaScript and TypeScript that uses V8 and built-in Rust. It is secure by default, so you must opt into each level of access your scripts need when running. This includes reading environment variables. It is for this reason that the Deno runtime was selected as I needed a secure sandbox to run external Javascript and Typescript programs.

Installation

The package can be installed by adding deno_ex to your list of dependencies in mix.exs:

def deps do
  [
    {:deno_ex, "~> 0.5.0"}
  ]
end

Installing the Runtime

By default Deno will automatically be installed in the package's priv directory as part of the compilation process. If you would like the build to place Deno in a different directory you may configure it. See the "Configuration" section of DenoEx.

Using DenoEx to Install Copies of the Runtime

Once you have DenoEx, you will need the Deno runtime. We have created a mix task that you can use to install Deno. By default, Deno will be installed in the priv directory for the deno_ex dependency. my_project/_build/dev/lib/deno_ex/priv/bin

mix deno_ex.install

The installation path may be changed using --path <path>. Permissions may also be changed on the deno executable using --chmod <octal>. The default permissions are 0x770.

Supporting DenoEx

If you rely on this library to run TypeScript and Javascript within your application, it would much appreciated if you can give back to the project in order to help ensure its continued development.

Checkout my GitHub Sponsorship page if you want to help out!

Gold Sponsors

Support the project

Silver Sponsors

Support the project

Bronze Sponsors

Support the project

Using DenoEx

Create a Typescript file with the following contents.

console.log("Hello, world.");

Open iex using iex -S mix and then run the TypeScript file:

iex > DenoEx.run({:file, "path/to/file.ts"})

Handling Dependencies

Scripts download dependencies on their first run. The output from downloading ends up in the scripts output. In order to avoid the time to download and vendoring at runtime we encourage users to vendor their dependencies. You will first need to configure vendoring.

config :deno_ex,
  scripts_path: [
    Path.join(~w[test support **]),
    Path.join(~w[my_scripts hello.ts])
  ]

scripts_path can be a list of paths to scripts or wildcards.

mix deno_ex.deps.get will load all dependencies in the cache and update the lock file.

In order to ensure that your scripts use the dependencies that are cached and locked your scripts need a few more arguments.

cached_only: true - tells the script to only used cached dependencies lock: path_to_lockfile - tells the script where the lock file is located