js_deno

    deno-specific js bindings

    js
    deno
    Download zip
    Author
    Version
    0.13.0
    License
    MIT
    Last updated
    14 days ago
    Downloads
    2K

    Dependencies

    #mizchi/js_deno

    MoonBit bindings for Deno runtime APIs.

    #Deno API Support Status

    CategoryAPIStatusNote
    Runtime
    Environment Variablesenv_get/set/delete/toObject🧪 TestedProcess environment
    Processcwd/exit/args🧪 TestedProcess information
    File System
    Read/Write TextreadTextFile/writeTextFile🧪 TestedText file operations
    Read/Write BinaryreadFile/writeFile🧪 TestedBinary file operations
    DirectoryreadDir/mkdir/remove🧪 TestedDirectory operations
    Testing
    Test Definitiontest_/test_async/test_only🧪 TestedTest framework
    Permissions
    Query/Request/Revokepermissions_*🧪 TestedPermission management
    PermissionStatusstate/is_granted🧪 TestedPermission state
    Subprocess
    CommandCommand::new/output/outputSync/spawn🧪 TestedProcess spawning
    CommandOutputcode/success/stdout/stderr🧪 TestedSubprocess output
    ChildProcessstatus/output/stdin/stdout/stderr🧪 TestedSpawned process
    Planned APIs
    Networkconnect/listen/serve📅 PlannedTCP/HTTP networking
    KVopenKv📅 PlannedKey-value storage
    FFIdlopen📅 PlannedForeign function interface
    WebGPUDeno.gpu📅 PlannedGPU acceleration

    #Status Legend

    • 🧪 Tested: Comprehensive test coverage
    • 📅 Planned: Scheduled for future implementation

    #Using Node.js APIs in Deno

    For APIs not yet implemented in the Deno-specific bindings, you can use Node.js compatibility packages:

    // Use Node.js fs instead of Deno's file APIs
    fn example() -> Unit {
    @js.run_async(fn() {
    let content = @fs_promises.readFile("file.txt", "utf-8").await
    @console.log(content)
    })
    }

    Deno provides built-in Node.js compatibility. See:


    #Installation

    Add to your moon.pkg.json:

    { "import": [ "mizchi/js", "mizchi/js_deno" ] }

    #API

    #Process/Runtime APIs

    • Deno::env_get(key) - Get environment variable
    • Deno::env_set(key, value) - Set environment variable
    • Deno::env_delete(key) - Delete environment variable
    • Deno::env_toObject() - Get all environment variables
    • Deno::cwd() - Get current working directory
    • Deno::exit(code?) - Exit the process
    • Deno::args() - Get command line arguments

    #File System APIs

    • Deno::readTextFile(path) - Read text file (returns Promise[String])
    • Deno::writeTextFile(path, data) - Write text file (returns Promise[Unit])
    • Deno::readFile(path) - Read file as Uint8Array (returns Promise[Js])
    • Deno::writeFile(path, data) - Write file from Uint8Array (returns Promise[Unit])
    • Deno::remove(path, recursive?) - Remove file or directory (returns Promise[Unit])
    • Deno::mkdir(path, recursive?) - Create directory (returns Promise[Unit])
    • Deno::readDir(path) - Read directory entries

    #Test APIs

    • Deno::test_(name, fn) - Define a test (synchronous)
    • Deno::test_async(name, fn) - Define a test (asynchronous)
    • Deno::test_only(name, fn) - Define a test marked as "only"

    #Permissions API

    • Deno::permissions_query(name, path?) - Query permission status (returns Promise[PermissionStatus])
    • Deno::permissions_request(name, path?) - Request permission (returns Promise[PermissionStatus])
    • Deno::permissions_revoke(name, path?) - Revoke permission (returns Promise[PermissionStatus])
    • PermissionStatus::state() - Get permission state ("granted", "denied", "prompt")
    • PermissionStatus::is_granted() - Check if permission is granted

    #Example

    fn main {
    let d = @deno.deno()

    // Environment variables
    d.env_set("MY_VAR", "hello")
    let value = d.env_get("MY_VAR")

    // Current directory
    let cwd = d.cwd()
    println(cwd)

    // Command line args
    let args = d.args()

    // File operations (async)
    d.writeTextFile("test.txt", "Hello, Deno!").await()
    let content = d.readTextFile("test.txt").await()
    println(content)

    // Permissions
    let status = d.permissions_query("read", path="/tmp").await()
    if status.is_granted() {
    println("Read permission granted")
    }
    }

    #Testing with Deno

    To use these bindings with Deno's test runner, create a test file:

    fn main {
    let d = @deno.deno()

    d.test_async("file operations", fn(_ctx) {
    d.writeTextFile("test.txt", "content").await()
    let result = d.readTextFile("test.txt").await()
    assert_eq(result, "content")
    d.remove("test.txt").await()
    })
    }

    Then run with:
    moon build --target js deno test --allow-all target/js/release/build/mizchi/js_deno/_tests/_tests.js

    #Notes

    • Most file system operations require --allow-read and --allow-write permissions
    • Network operations require --allow-net permission
    • Environment variable access requires --allow-env permission
    • For testing, use --allow-all or specify individual permissions

    #Status

    This is a basic implementation of Deno APIs. More APIs will be added as needed.

    ChildProcess

    #external
    pub type ChildProcess

    ChildProcess - spawned subprocess https://docs.deno.com/api/deno/~/Deno.ChildProcess

    ChildProcess::as_any

    ChildProcess::kill

    fn ChildProcess::kill(self : ChildProcess, signal? : String) -> Unit

    Send signal to process

    ChildProcess::pid

    fn ChildProcess::pid(self : ChildProcess) -> Int

    Get process ID

    ChildProcess::ref_

    fn ChildProcess::ref_(self : ChildProcess) -> Unit

    Allow process to keep event loop alive (default)

    ChildProcess::status

    async fn ChildProcess::status(self : ChildProcess) -> CommandStatus

    Wait for process to complete

    ChildProcess::stderr

    Get stderr stream (ReadableStream)

    ChildProcess::stdin

    Get stdin stream (WritableStream)

    ChildProcess::stdout

    Get stdout stream (ReadableStream)

    ChildProcess::unref

    fn ChildProcess::unref(self : ChildProcess) -> Unit

    Prevent process from keeping event loop alive

    Command

    #external
    pub type Command

    Command type for creating subprocesses https://docs.deno.com/api/deno/~/Deno.Command

    Command::as_any

    fn Command::as_any(self : Command) ->
    Any

    Command::new

    fn Command::new(program : String, args? : Array[String], cwd? : String, env? :
    Any
    , stdin? : String, stdout? : String, stderr? : String) -> Command

    Create a new Command to run a program

    Command::output

    async fn Command::output(self : Command) -> CommandOutput

    Execute command and collect output https://docs.deno.com/api/deno/~/Deno.Command#method_output_0

    Command::outputSync

    #alias(output_sync)
    fn Command::outputSync(self : Command) -> CommandOutput

    Execute command synchronously and collect output https://docs.deno.com/api/deno/~/Deno.Command#method_outputSync_0

    Command::spawn

    fn Command::spawn(self : Command) -> ChildProcess

    Spawn a subprocess https://docs.deno.com/api/deno/~/Deno.Command#method_spawn_0

    CommandOutput

    #external
    pub type CommandOutput

    CommandOutput - result of Command.output()

    CommandOutput::as_any

    CommandOutput::code

    fn CommandOutput::code(self : CommandOutput) -> Int

    Get exit code from CommandOutput

    CommandOutput::signal

    fn CommandOutput::signal(self : CommandOutput) -> String?

    Get signal that terminated the process (if any)

    CommandOutput::stderr

    Get stderr as Uint8Array

    CommandOutput::stdout

    Get stdout as Uint8Array

    CommandOutput::success

    fn CommandOutput::success(self : CommandOutput) -> Bool

    Check if command succeeded (exit code 0)

    CommandStatus

    #external
    pub type CommandStatus

    CommandStatus - result of waiting for process

    CommandStatus::as_any

    CommandStatus::code

    fn CommandStatus::code(self : CommandStatus) -> Int

    Get exit code from CommandStatus

    CommandStatus::signal

    fn CommandStatus::signal(self : CommandStatus) -> String?

    Get signal that terminated the process (if any)

    CommandStatus::success

    fn CommandStatus::success(self : CommandStatus) -> Bool

    Check if command succeeded

    Deno

    #external
    pub type Deno

    Deno::args

    fn Deno::args(self : Deno) -> Array[String]

    Get command line arguments

    Note: The returned array is a snapshot and should be treated as immutable.

    Deno::as_any

    fn Deno::as_any(self : Deno) ->
    Any

    Deno::build_arch

    fn Deno::build_arch(self : Deno) -> String

    Get architecture

    Deno::build_os

    fn Deno::build_os(self : Deno) -> String

    Get operating system

    Deno::chmod

    async fn Deno::chmod(self : Deno, path : String, mode : Int) -> Unit

    Change file permissions (Unix only)

    Deno::connect

    async fn Deno::connect(self : Deno, hostname : String, port : Int) ->
    Any

    Open a network connection (TCP)

    Deno::copyFile

    async fn Deno::copyFile(self : Deno, from : String, to : String) -> Unit

    Copy file

    Deno::create

    async fn Deno::create(self : Deno, path : String) -> FsFile

    Create a file

    Deno::cwd

    fn Deno::cwd(self : Deno) -> String

    Get current working directory

    Deno::env_delete

    fn Deno::env_delete(self : Deno, key : String) -> Unit

    Delete environment variable

    Deno::env_get

    fn Deno::env_get(self : Deno, key : String) -> String?

    Get environment variable

    Deno::env_set

    fn Deno::env_set(self : Deno, key : String, value : String) -> Unit

    Set environment variable

    Deno::env_toObject

    fn Deno::env_toObject(self : Deno) ->
    Any

    Get all environment variables

    Deno::exit

    fn Deno::exit(self : Deno, code? : Int) -> Unit

    Exit the process

    Deno::gid

    fn Deno::gid(self : Deno) -> Int?

    Get group ID (Unix only)

    Deno::hostname

    fn Deno::hostname(self : Deno) -> String

    Get hostname

    Deno::listen

    fn Deno::listen(self : Deno, hostname : String, port : Int) ->
    Any

    Listen on a network address (TCP server)

    Deno::loadavg

    fn Deno::loadavg(self : Deno) -> Array[Double]

    Get system load average (Unix only)

    Note: The returned array is a snapshot and should be treated as immutable.

    Deno::lstat

    async fn Deno::lstat(self : Deno, path : String) ->
    Any

    Check if path exists (returns null if not found instead of throwing)

    Deno::makeTempDir

    async fn Deno::makeTempDir(self : Deno, prefix? : String) -> String

    Make temporary directory

    Deno::makeTempFile

    async fn Deno::makeTempFile(self : Deno, prefix? : String) -> String

    Make temporary file

    Deno::mkdir

    async fn Deno::mkdir(self : Deno, path : String, recursive? : Bool) -> Unit

    Create directory

    Deno::networkInterfaces

    fn Deno::networkInterfaces(self : Deno) ->
    Any

    Get network interfaces

    Deno::now

    fn Deno::now(self : Deno) -> Double

    Get high resolution time (uses performance.now())

    Deno::open

    async fn Deno::open(self : Deno, path : String, create? : Bool, write? : Bool, read? : Bool) -> FsFile

    Open a file

    Deno::osRelease

    fn Deno::osRelease(self : Deno) -> String

    Get OS release version

    Deno::osUptime

    fn Deno::osUptime(self : Deno) -> Int

    Get OS uptime in seconds

    Deno::permissions

    fn Deno::permissions(self : Deno) ->
    Any

    Get permissions object

    Deno::permissions_query

    async fn Deno::permissions_query(self : Deno, name : String, path? : String) -> PermissionStatus

    Query permission status

    Deno::permissions_request

    async fn Deno::permissions_request(self : Deno, name : String, path? : String) -> PermissionStatus

    Request permission

    Deno::permissions_revoke

    async fn Deno::permissions_revoke(self : Deno, name : String, path? : String) -> PermissionStatus

    Revoke permission

    Deno::pid

    fn Deno::pid(self : Deno) -> Int

    Get process ID

    Deno::ppid

    fn Deno::ppid(self : Deno) -> Int

    Get parent process ID

    Deno::readDir

    fn Deno::readDir(self : Deno, path : String) ->
    Any

    Read directory entries

    Deno::readFile

    async fn Deno::readFile(self : Deno, path : String) ->
    Uint8Array

    Read file as Uint8Array
    async fn Deno::readLink(self : Deno, path : String) -> String

    Read link target

    Deno::readTextFile

    async fn Deno::readTextFile(self : Deno, path : String) -> String

    Read text file

    Deno::realPath

    async fn Deno::realPath(self : Deno, path : String) -> String

    Get real path (resolves symlinks)

    Deno::remove

    async fn Deno::remove(self : Deno, path : String, recursive? : Bool) -> Unit

    Remove file or directory

    Deno::rename

    async fn Deno::rename(self : Deno, oldpath : String, newpath : String) -> Unit

    Rename/move file or directory

    Deno::resolveDns

    async fn Deno::resolveDns(self : Deno, query : String, recordType : String) ->
    Any

    Resolve DNS hostname to IP addresses

    Deno::serve

    fn Deno::serve(self : Deno, port : Int, handler :
    Any
    ) ->
    Any

    Serve HTTP requests (simplified version)

    Deno::stat

    async fn Deno::stat(self : Deno, path : String) ->
    Any

    Check if path exists

    Deno::stderr_write

    async fn Deno::stderr_write(self : Deno, data :
    Any
    ) -> Int

    Write to stderr

    Deno::stdin_read

    async fn Deno::stdin_read(self : Deno) ->
    Any

    Read all data from stdin

    Deno::stdout_write

    async fn Deno::stdout_write(self : Deno, data :
    Any
    ) -> Int

    Write to stdout
    async fn Deno::symlink(self : Deno, target : String, path : String) -> Unit

    Create symbolic link

    Deno::systemMemoryInfo

    fn Deno::systemMemoryInfo(self : Deno) ->
    Any

    Get system memory info

    Deno::test_

    fn Deno::test_(self : Deno, name : String, f : (TestContext) -> Unit) -> Unit

    Deno.test(name, fn)

    Deno::test_async

    fn Deno::test_async(self : Deno, name : String, f : async (TestContext) -> Unit) -> Unit

    Deno.test(name, async fn)

    Deno::test_only

    fn Deno::test_only(self : Deno, name : String, f : async (TestContext) -> Unit) -> Unit

    Deno.test with options (simplified - use only for testing async functions with basic options)

    Deno::truncate

    async fn Deno::truncate(self : Deno, name : String, len : Int) -> Unit

    Truncate or extend a file to specified length

    Deno::uid

    fn Deno::uid(self : Deno) -> Int?

    Get user ID (Unix only)

    Deno::writeFile

    async fn Deno::writeFile(self : Deno, path : String, data :
    Any
    ) -> Unit

    Write file from Uint8Array or ArrayBuffer

    Deno::writeTextFile

    async fn Deno::writeTextFile(self : Deno, path : String, data : String) -> Unit

    Write text file

    FsFile

    #external
    pub type FsFile

    FsFile::as_any

    fn FsFile::as_any(self : FsFile) ->
    Any

    FsFile::close

    fn FsFile::close(self : FsFile) -> Unit

    Close file handle

    FsFile::read

    async fn FsFile::read(self : FsFile, buffer :
    Any
    ) -> Int

    Read from file

    FsFile::seek

    async fn FsFile::seek(self : FsFile, offset : Int, whence : Int) -> Int

    Seek file position

    FsFile::write

    async fn FsFile::write(self : FsFile, data :
    Any
    ) -> Int

    Write to file

    PermissionStatus

    #external
    pub type PermissionStatus

    PermissionStatus::as_any

    PermissionStatus::is_granted

    fn PermissionStatus::is_granted(self : PermissionStatus) -> Bool

    Check if permission is granted

    PermissionStatus::state

    fn PermissionStatus::state(self : PermissionStatus) -> String

    Get permission state ("granted", "denied", "prompt")

    TestContext

    #external
    pub type TestContext

    TestContext::as_any

    deno

    fn deno() -> Deno

    Deno global object

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io