-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
115 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* Finds the instances of an executable in the system path. | ||
*/ | ||
export declare class Finder { | ||
#private; | ||
/** | ||
* The list of executable file extensions. | ||
*/ | ||
readonly extensions: Set<string>; | ||
/** | ||
* The list of system paths. | ||
*/ | ||
readonly paths: Set<string>; | ||
/** | ||
* Creates a new finder. | ||
* @param options An object providing values to initialize this instance. | ||
*/ | ||
constructor(options?: FinderOptions); | ||
/** | ||
* Value indicating whether the current platform is Windows. | ||
*/ | ||
static get isWindows(): boolean; | ||
/** | ||
* Finds the instances of an executable in the system path. | ||
* @param command The command to be resolved. | ||
* @returns The paths of the executables found. | ||
*/ | ||
find(command: string): AsyncGenerator<string, void>; | ||
/** | ||
* Gets a value indicating whether the specified file is executable. | ||
* @param file The path of the file to be checked. | ||
* @returns `true` if the specified file is executable, otherwise `false`. | ||
*/ | ||
isExecutable(file: string): Promise<boolean>; | ||
} | ||
/** | ||
* Defines the options of a {@link Finder} instance. | ||
*/ | ||
export type FinderOptions = Partial<{ | ||
/** | ||
* The list of executable file extensions. | ||
*/ | ||
extensions: Array<string>; | ||
/** | ||
* The list of system paths. | ||
*/ | ||
paths: Array<string>; | ||
}>; | ||
//# sourceMappingURL=finder.d.ts.map |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import {Finder} from "./finder.js"; | ||
|
||
/** | ||
* Provides convenient access to the stream of search results. | ||
*/ | ||
export class ResultSet { | ||
|
||
/** | ||
* Creates a new result set. | ||
* @param command The searched command. | ||
* @param finder The finder used to perform the search. | ||
*/ | ||
constructor(command: string, finder: Finder); | ||
|
||
/** | ||
* Returns all instances of the searched command. | ||
* @returns All search results. | ||
*/ | ||
all(): Promise<Array<string>>; | ||
|
||
/** | ||
* Returns the first instance of the searched command. | ||
* @returns The first search result. | ||
*/ | ||
first(): Promise<string>; | ||
|
||
/** | ||
* Returns a stream of instances of the searched command. | ||
* @returns A stream of the search results. | ||
*/ | ||
stream(): AsyncGenerator<string, void>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Finds the instances of an executable in the system path. | ||
export class Finder |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import {delimiter} from "node:path"; | ||
import {Finder} from "./finder.js"; | ||
|
||
# Provides convenient access to the stream of search results. | ||
export class ResultSet | ||
|
||
# Creates a new result set. | ||
constructor: (command, finder) -> | ||
|
||
# The searched command. | ||
@_command = command | ||
|
||
# The finder used to perform the search. | ||
@_finder = finder | ||
|
||
# Returns all instances of the searched command. | ||
all: -> | ||
executables = new Set | ||
executables.add path for await path from @stream() | ||
if executables.size then Array.from executables else | ||
paths = Array.from(@_finder.paths).join if Finder.isWindows then ";" else delimiter | ||
throw Error "No \"#{@_command}\" in (#{paths})." | ||
|
||
# Returns the first instance of the searched command. | ||
first: -> | ||
{value} = await @stream().next() | ||
if value then value else | ||
paths = Array.from(@_finder.paths).join if Finder.isWindows then ";" else delimiter | ||
throw Error "No \"#{@_command}\" in (#{paths})." | ||
|
||
# Returns a stream of instances of the searched command. | ||
stream: -> @_finder.find @_command |
This file was deleted.
Oops, something went wrong.
Empty file.
Empty file.