View Source DenoEx (DenoEx v0.5.0)
DenoEx is used to run javascript and typescript files in a safe environment by utilizing Deno.
Basics
Configuration
Configuration of the deno installation directory can be set in a few ways. We can use an
environment variable, application config, or pass it directly to the run command. The
different configurations are there to facilitate different working situations. The
priorities are function options
> application configuration
> environment
.
Function Option
iex> DenoEx.run({:file, Path.join(~w[test support hello.ts])}, [], [deno_location: "/Users/akoutmos/Documents/opensource/deno_ex/_build/dev/lib/deno_ex/priv/bin"])
{:ok, "Hello, world.\n"}
Application Configuration
import Config
config :deno_ex,
exectutable_location: Path.join(~w[path containing deno])
ENV Variable
DENO_LOCATION=path
Summary
Types
The arguments for deno
The path to the script that should be executed, or a tuple denoting what should be passed to the Deno executable over STDIN.
The list of arguements to be passed to the script
Functions
Returns the location where the deno script is expected to be located.
Returns the default import map path
Locks the Deno dependencies
Returns the default lock file path
Uses deno run
to run a Deno script.
Vendors Deno dependencies into the given location
Returns the vendor location where deno script dependencies will be stored
Types
@type options() :: DenoEx.Pipe.options()
The arguments for deno
@type script() :: {:file, Path.t()} | {:stdin, IO.chardata()}
The path to the script that should be executed, or a tuple denoting what should be passed to the Deno executable over STDIN.
@type script_arguments() :: [String.t()]
The list of arguements to be passed to the script
Functions
@spec executable_path() :: String.t()
Returns the location where the deno script is expected to be located.
Returns the default import map path
Locks the Deno dependencies
Returns the default lock file path
run(script, script_arguments \\ [], options \\ [], timeout \\ :timer.seconds(5))
View Source@spec run(script(), script_arguments(), options(), timeout()) :: {:ok | :error, String.t()}
Uses deno run
to run a Deno script.
Options
:deno_location
(String.t/0
) - Sets the path where the deno executable is located.
Note: It does not include the deno executable. If the executable is located at
/usr/bin/deno
then the deno_location
should be /usr/bin
.
:allow_env
- Allows read and write access to environment variables.true
: allows full access to the environment variables[String.t()]
: allows access to only the subset of variables in the list.:allow_sys
- Allows access to APIs that provide system information. i.e. hostname, memory usagetrue
: allows full access[String.t()]
: allows access to only the subset calls. hostname, osRelease, osUptime, loadavg, networkInterfaces, systemMemoryInfo, uid, and gid:allow_net
- Allows network access.true
: allows full access to the network[String.t()]
: allows access to only the network connections specified ie. 127.0.0.1:4000, 127.0.0.1, :4001:allow_hrtime
(boolean/0
) - Allows high-resolution time measurement. High-resolution time can be used in timing attacks and fingerprinting.:allow_ffi
- Allow loading of dynamic libraries.WARNING:
Be aware that dynamic libraries are not run in a sandbox and therefore do not have the same security restrictions as the Deno process. Therefore, use it with caution.
true
: allows all dlls to be accessed[Path.t()]
: A list of paths to dlls that will be accessible:allow_run
- Allow running subprocesses.WARNING
Be aware that subprocesses are not run in a sandbox and therefore do not have the same security restrictions as the Deno process. Therefore, use it with caution.
true
: allows all subprocesses to be run[Path.t()]
: A list of subprocesses to run:allow_write
- Allow the ability to write files.true
: allows all files to be written[Path.t()]
: A list of files that can be written:allow_read
- Allow the ability to read files.true
: allows all files to be read[Path.t()]
: A list of files that can be read:allow_all
(boolean/0
) - Turns on all options and bypasses all security measures:no_remote
(boolean/0
) - Disallows installing of imports from remote locations:import_map
(String.t/0
) - The location of the import map json file for finding vendored dependencies:lock
(String.t/0
) - The location of the lock file for running scripts:cached_only
(boolean/0
) - Only allows chaced dependencies to be usedPlease refer to Deno Permissions for more details.
Examples
iex> DenoEx.run({:file, Path.join(~w[test support hello.ts])})
{:ok, "Hello, world.\n"}
iex> DenoEx.run({:file, Path.join(~w[test support args_echo.ts])}, ~w[foo bar])
{:ok, "foo bar\n"}
iex> DenoEx.run({:stdin, "console.log(\"Hello, world.\")"})
{:ok, "Hello, world.\n"}
vendor_dependencies(script_paths, vendor_location, lock_file_location, args)
View SourceVendors Deno dependencies into the given location
Returns the vendor location where deno script dependencies will be stored