Skip to main content

@libs/run@3.3.2
Built and signed on GitHub Actions

Works with
This package works with Deno
This package works with Deno
JSR Score94%
License
MIT
Downloads13/wk
Published3 weeks ago (3.3.2)

⏯️ Utilities to run subprocess.

⏯️ Run subprocesses

JSR JSR Score NPM Coverage

Warning

Deno exclusive!

📑 Examples

Run a command

import { command } from "./command.ts"

// Commands are run asynchronously, and support Deno.command options alongside additional options
// For example, stdio can also be set to a Logger level too or you can automatically append an extension when running on Windows
await command("deno", ["--version"], { stdout: "debug", stderr: "piped", winext: ".exe" })

// Commands can be run synchronously too, and can also throw an error automatically when the process exits with a non-zero code
command("deno", ["--version"], { sync: true, throw: true })

Writing to stdin

import { command } from "./command.ts"

const { stdout } = await command("deno", ["repl"], {
  env: { NO_COLOR: "true" },
  // Passing a callback will automatically set `stdin` to `"piped"`
  // You can then write to the process using utility functions
  callback: async ({ i, stdio, write, close, wait }) => {
    if ((!stdio.stdout.includes("exit using")) || i) {
      return
    }
    await write("console.log('hello')")
    await wait(1000)
    close()
  },
})
console.assert(stdout.includes("hello"))

✨ Features

  • Supports stdin interactivity through callbacks.
    • Make it possible to monitor stdout and stderr content and react accordingly.
  • Auto-detects os and can automatically append an extension when running on Windows.
  • Supports both sync and async modes in a single function.
    • Optionally decide to throw an error when the process exits with a non-zero code.
  • Generates a stdio history that contains timestamped entries with configurable buffering

🕊️ Migrating from 2.x.x to 3.x.x

Version 3.x.x and onwards require Deno 2.x.x or later.

📜 Licenses

Copyright (c) Simon Lecoq <@lowlighter>. (MIT License)
https://github.com/lowlighter/libs/blob/main/LICENSE
Built and signed on
GitHub Actions

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@libs/run

Import symbol

import * as run from "@libs/run";
or

Import directly with a jsr specifier

import * as run from "jsr:@libs/run";