From f07ffe89806392698fb8052691b2826f82f15bbe Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Sat, 21 Dec 2019 11:30:13 +0000 Subject: [PATCH] feat: Add Deno.dir("executable") (#3526) --- cli/js/lib.deno_runtime.d.ts | 14 +++++++++++--- cli/js/os.ts | 14 +++++++++++--- cli/js/os_test.ts | 8 ++++++++ cli/ops/os.rs | 1 + 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/cli/js/lib.deno_runtime.d.ts b/cli/js/lib.deno_runtime.d.ts index e667d497d86a1a..d955c09bf318aa 100644 --- a/cli/js/lib.deno_runtime.d.ts +++ b/cli/js/lib.deno_runtime.d.ts @@ -59,6 +59,7 @@ declare namespace Deno { | "home" | "cache" | "config" + | "executable" | "data" | "data_local" | "audio" @@ -77,9 +78,9 @@ declare namespace Deno { * Returns null if there is no applicable directory or if any other error * occurs. * - * Argument values: "home", "cache", "config", "data", "data_local", "audio", - * "desktop", "document", "download", "font", "picture", "public", "template", - * "video" + * Argument values: "home", "cache", "config", "executable", "data", + * "data_local", "audio", "desktop", "document", "download", "font", "picture", + * "public", "template", "video" * * "cache" * |Platform | Value | Example | @@ -95,6 +96,13 @@ declare namespace Deno { * | macOS | `$HOME`/Library/Preferences | /Users/Alice/Library/Preferences | * | Windows | `{FOLDERID_RoamingAppData}` | C:\Users\Alice\AppData\Roaming | * + * "executable" + * |Platform | Value | Example | + * | ------- | --------------------------------------------------------------- | -----------------------| + * | Linux | `XDG_BIN_HOME` or `$XDG_DATA_HOME`/../bin or `$HOME`/.local/bin | /home/alice/.local/bin | + * | macOS | - | - | + * | Windows | - | - | + * * "data" * |Platform | Value | Example | * | ------- | ---------------------------------------- | ---------------------------------------- | diff --git a/cli/js/os.ts b/cli/js/os.ts index 8e91be4affed57..c2d7a8f7866b9f 100644 --- a/cli/js/os.ts +++ b/cli/js/os.ts @@ -133,6 +133,7 @@ type DirKind = | "home" | "cache" | "config" + | "executable" | "data" | "data_local" | "audio" @@ -151,9 +152,9 @@ type DirKind = * Returns null if there is no applicable directory or if any other error * occurs. * - * Argument values: "home", "cache", "config", "data", "data_local", "audio", - * "desktop", "document", "download", "font", "picture", "public", "template", - * "video" + * Argument values: "home", "cache", "config", "executable", "data", + * "data_local", "audio", "desktop", "document", "download", "font", "picture", + * "public", "template", "video" * * "cache" * |Platform | Value | Example | @@ -169,6 +170,13 @@ type DirKind = * | macOS | `$HOME`/Library/Preferences | /Users/Alice/Library/Preferences | * | Windows | `{FOLDERID_RoamingAppData}` | C:\Users\Alice\AppData\Roaming | * + * "executable" + * |Platform | Value | Example | + * | ------- | --------------------------------------------------------------- | -----------------------| + * | Linux | `XDG_BIN_HOME` or `$XDG_DATA_HOME`/../bin or `$HOME`/.local/bin | /home/alice/.local/bin | + * | macOS | - | - | + * | Windows | - | - | + * * "data" * |Platform | Value | Example | * | ------- | ---------------------------------------- | ---------------------------------------- | diff --git a/cli/js/os_test.ts b/cli/js/os_test.ts index 55a62792d4527d..749c25d830ecbb 100644 --- a/cli/js/os_test.ts +++ b/cli/js/os_test.ts @@ -146,6 +146,14 @@ testPerm({ env: true }, function getDir(): void { { os: "linux", shouldHaveValue: true } ] }, + { + kind: "executable", + runtime: [ + { os: "mac", shouldHaveValue: false }, + { os: "win", shouldHaveValue: false }, + { os: "linux", shouldHaveValue: true } + ] + }, { kind: "data", runtime: [ diff --git a/cli/ops/os.rs b/cli/ops/os.rs index 03f81838ccab3b..c42827b3fb06b8 100644 --- a/cli/ops/os.rs +++ b/cli/ops/os.rs @@ -75,6 +75,7 @@ fn op_get_dir( "home" => dirs::home_dir(), "config" => dirs::config_dir(), "cache" => dirs::cache_dir(), + "executable" => dirs::executable_dir(), "data" => dirs::data_dir(), "data_local" => dirs::data_local_dir(), "audio" => dirs::audio_dir(),