Shared GenServer dispatch logic for Run modules.
This module provides a __using__ macro that injects GenServer boilerplate,
a common public API, and stdout dispatch logic for both the NIF-backed
Denox.Run and the CLI-backed Denox.CLI.Run.
Public API (injected into using modules)
Lifecycle: start_link/1, stop/1
I/O: send/2, recv/2, send_and_recv/3
Pub/Sub: subscribe/1, unsubscribe/1
Introspection: alive?/1, os_pid/1
Convenience (one-shot):
capture/1— start, collect all lines, stop; returns{:ok, [String.t()]}stream/1— start + lazyStream(auto-stops on halt)stream_from/2— lazyStreamfrom an existing PID (caller manages lifecycle)with_runtime/2— start + user function + guaranteed stop viaafter
Implementing a Backend
Modules that use Denox.Run.Base, backend: :my_backend must implement four
callbacks:
init_backend/1— start the backend (NIF resource or Port)send_backend/2— write data to the backend's stdinstop_backend/1— shut down the backendalive_backend?/1— check if the backend is still running
See Denox.Run (NIF backend) and Denox.CLI.Run (subprocess backend) for
concrete implementations.
Summary
Functions
Resolve a specifier to a form suitable for the Deno runtime.
Callbacks
Functions
Resolve a specifier to a form suitable for the Deno runtime.
Rules
- Specifiers already prefixed with
npm:,jsr:,http://,https://, orfile://are passed through unchanged. - Scoped package names starting with
@are prefixed withnpm:. - Everything else is returned as-is (treated as a file path by the backend).
Examples
iex> Denox.Run.Base.resolve_specifier("npm:cowsay")
"npm:cowsay"
iex> Denox.Run.Base.resolve_specifier("@scope/pkg")
"npm:@scope/pkg"
iex> Denox.Run.Base.resolve_specifier("server.ts")
"server.ts"