Skip to main content
Home

@gnome/exec@0.6.0
Built and signed on GitHub Actions

A cross-runtime module for invoking executables similar to child_process and Deno's Deno.Command.

This package works with Node.js, Deno, Bun
This package works with Node.js
This package works with Deno
This package works with Bun
JSR Score
94%
Published
a year ago (0.6.0)
class PathFinder

Represents a path finder that allows storing and retrieving options for finding an executable and methods to find the executable.

The path finder will use the options to look up by precendence:

  • If the full path to the executable is provided, it will be used.
  • If an environment variable is provided, it will be used.
  • If a cached path is provided, it will be used.
  • If the executable is found in the system path, it will be used.
  • If the executable is found in the windows paths when on Windows, it will be used.
  • If the executable is found in the darwin paths when on Darwin or linux paths, it will be used.
  • If the executable is found in the linux paths, it will be used.

The paths for windows, darwin, and linux can contain environment variables e.g. ${USERPROFILE}, ${USER}, or `%USERPROFILE% that will be expanded before checking if the file exists.

Examples

Example 1

import { pathFinder } from "./path-finder.ts";

pathFinder.set("deno", {
   name: "deno",
   envVariable: "DENO_EXE",
   windows: ["${USERPROFILE}\\.deno\\bin\\deno.exe"],
   linux: ["${USER}/.deno/bin/deno"],
});

const deno = await pathFinder.findExe("deno");
console.log(deno);

Constructors

new
PathFinder()

Methods

clear(): void

Clears all path finders.

Deletes the path finder with the given name.

find(name: string): PathFinderOptions | undefined

Finds the path finder options for a given name.

findExe(name: string): Promise<string | undefined>

Finds the executable path for a given name.

findExeSync(name: string): string | undefined

Synchronously finds the executable path for a given name.

get(name: string): PathFinderOptions | undefined

Retrieves the path finder options for a given name.

Checks if a path finder with the given name exists.

set(
name: string,
): void

Sets the path finder options for a given name.

New Ticket: 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:@gnome/exec

Import symbol

import { PathFinder } from "@gnome/exec/path-finder";
or

Import directly with a jsr specifier

import { PathFinder } from "jsr:@gnome/exec/path-finder";

Add Package

pnpm i jsr:@gnome/exec
or (using pnpm 10.8 or older)
pnpm dlx jsr add @gnome/exec

Import symbol

import { PathFinder } from "@gnome/exec/path-finder";

Add Package

yarn add jsr:@gnome/exec
or (using Yarn 4.8 or older)
yarn dlx jsr add @gnome/exec

Import symbol

import { PathFinder } from "@gnome/exec/path-finder";

Add Package

vlt install jsr:@gnome/exec

Import symbol

import { PathFinder } from "@gnome/exec/path-finder";

Add Package

npx jsr add @gnome/exec

Import symbol

import { PathFinder } from "@gnome/exec/path-finder";

Add Package

bunx jsr add @gnome/exec

Import symbol

import { PathFinder } from "@gnome/exec/path-finder";