summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorecyrbe <ecyrbe@gmail.com>2020-03-02 01:05:04 +0100
committerGitHub <noreply@github.com>2020-03-01 19:05:04 -0500
commit2a594bd3b2403fbbd26a0191ac8c289c365451d0 (patch)
tree0b620a57e80ff1651f230ae0f6458145d1017cde
parentad21210edd5aabdeebe70809672b4224cc6f41c9 (diff)
feat(std/node): add os.tmpdir() implementation (#4213)
-rw-r--r--cli/js/lib.deno.ns.d.ts11
-rw-r--r--cli/js/os.ts9
-rw-r--r--cli/js/os_test.ts8
-rw-r--r--cli/ops/os.rs1
-rw-r--r--std/node/os.ts6
-rw-r--r--std/node/os_test.ts14
6 files changed, 38 insertions, 11 deletions
diff --git a/cli/js/lib.deno.ns.d.ts b/cli/js/lib.deno.ns.d.ts
index 0bd176a9f..b2e67b288 100644
--- a/cli/js/lib.deno.ns.d.ts
+++ b/cli/js/lib.deno.ns.d.ts
@@ -116,6 +116,7 @@ declare namespace Deno {
| "picture"
| "public"
| "template"
+ | "tmp"
| "video";
// TODO(ry) markdown in jsdoc broken https://deno.land/typedoc/index.html#dir
@@ -131,7 +132,7 @@ declare namespace Deno {
*
* Argument values: `"home"`, `"cache"`, `"config"`, `"executable"`, `"data"`,
* `"data_local"`, `"audio"`, `"desktop"`, `"document"`, `"download"`,
- * `"font"`, `"picture"`, `"public"`, `"template"`, `"video"`
+ * `"font"`, `"picture"`, `"public"`, `"template"`, `"tmp"`, `"video"`
*
* `"cache"`
*
@@ -237,6 +238,14 @@ declare namespace Deno {
* | macOS | – | – |
* | Windows | `{FOLDERID_Templates}` | C:\Users\Alice\AppData\Roaming\Microsoft\Windows\Templates |
*
+ * `"tmp"`
+ *
+ * |Platform | Value | Example |
+ * | ------- | ---------------------- | ---------------------------------------------------------- |
+ * | Linux | `TMPDIR` | /tmp |
+ * | macOS | `TMPDIR` | /tmp |
+ * | Windows | `{TMP}` | C:\Users\Alice\AppData\Local\Temp |
+ *
* `"video"`
*
* |Platform | Value | Example |
diff --git a/cli/js/os.ts b/cli/js/os.ts
index 309f5e1ff..89632e34f 100644
--- a/cli/js/os.ts
+++ b/cli/js/os.ts
@@ -88,6 +88,7 @@ type DirKind =
| "picture"
| "public"
| "template"
+ | "tmp"
| "video";
/**
@@ -191,6 +192,14 @@ type DirKind =
* | macOS | – | – |
* | Windows | `{FOLDERID_Templates}` | C:\Users\Alice\AppData\Roaming\Microsoft\Windows\Templates |
*
+ * "tmp"
+ *
+ * |Platform | Value | Example |
+ * | ------- | ---------------------- | ---------------------------------------------------------- |
+ * | Linux | `TMPDIR` | /tmp |
+ * | macOS | `TMPDIR` | /tmp |
+ * | Windows | `{TMP}` | C:\Users\Alice\AppData\Local\Temp |
+ *
* "video"
* |Platform | Value | Example |
* | ------- | ------------------- | --------------------- |
diff --git a/cli/js/os_test.ts b/cli/js/os_test.ts
index 6825b7b0d..b0561840b 100644
--- a/cli/js/os_test.ts
+++ b/cli/js/os_test.ts
@@ -235,6 +235,14 @@ testPerm({ env: true }, function getDir(): void {
]
},
{
+ kind: "tmp",
+ runtime: [
+ { os: "mac", shouldHaveValue: true },
+ { os: "win", shouldHaveValue: true },
+ { os: "linux", shouldHaveValue: true }
+ ]
+ },
+ {
kind: "video",
runtime: [
{ os: "mac", shouldHaveValue: true },
diff --git a/cli/ops/os.rs b/cli/ops/os.rs
index 2df9470dd..428856707 100644
--- a/cli/ops/os.rs
+++ b/cli/ops/os.rs
@@ -49,6 +49,7 @@ fn op_get_dir(
"picture" => dirs::picture_dir(),
"public" => dirs::public_dir(),
"template" => dirs::template_dir(),
+ "tmp" => Some(std::env::temp_dir()),
"video" => dirs::video_dir(),
_ => {
return Err(
diff --git a/std/node/os.ts b/std/node/os.ts
index f34551da9..4bc70d1ff 100644
--- a/std/node/os.ts
+++ b/std/node/os.ts
@@ -180,9 +180,9 @@ export function setPriority(pid: number, priority?: number): void {
notImplemented(SEE_GITHUB_ISSUE);
}
-/** Not yet implemented */
-export function tmpdir(): string {
- notImplemented(SEE_GITHUB_ISSUE);
+/** Returns the operating system's default directory for temporary files as a string. */
+export function tmpdir(): string | null {
+ return Deno.dir("tmp");
}
/** Not yet implemented */
diff --git a/std/node/os_test.ts b/std/node/os_test.ts
index 6ef123575..a73a2d4e9 100644
--- a/std/node/os_test.ts
+++ b/std/node/os_test.ts
@@ -17,6 +17,13 @@ test({
});
test({
+ name: "tmp directory is a string",
+ fn() {
+ assertEquals(typeof os.tmpdir(), "string");
+ }
+});
+
+test({
name: "hostname is a string",
fn() {
assertEquals(typeof os.hostname(), "string");
@@ -232,13 +239,6 @@ test({
);
assertThrows(
() => {
- os.tmpdir();
- },
- Error,
- "Not implemented"
- );
- assertThrows(
- () => {
os.totalmem();
},
Error,