mirror of
https://github.com/denoland/deno.git
synced 2024-12-25 00:29:09 -05:00
feat(std/node): add os.tmpdir() implementation (#4213)
This commit is contained in:
parent
ad21210edd
commit
2a594bd3b2
6 changed files with 38 additions and 11 deletions
11
cli/js/lib.deno.ns.d.ts
vendored
11
cli/js/lib.deno.ns.d.ts
vendored
|
@ -116,6 +116,7 @@ declare namespace Deno {
|
||||||
| "picture"
|
| "picture"
|
||||||
| "public"
|
| "public"
|
||||||
| "template"
|
| "template"
|
||||||
|
| "tmp"
|
||||||
| "video";
|
| "video";
|
||||||
|
|
||||||
// TODO(ry) markdown in jsdoc broken https://deno.land/typedoc/index.html#dir
|
// 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"`,
|
* Argument values: `"home"`, `"cache"`, `"config"`, `"executable"`, `"data"`,
|
||||||
* `"data_local"`, `"audio"`, `"desktop"`, `"document"`, `"download"`,
|
* `"data_local"`, `"audio"`, `"desktop"`, `"document"`, `"download"`,
|
||||||
* `"font"`, `"picture"`, `"public"`, `"template"`, `"video"`
|
* `"font"`, `"picture"`, `"public"`, `"template"`, `"tmp"`, `"video"`
|
||||||
*
|
*
|
||||||
* `"cache"`
|
* `"cache"`
|
||||||
*
|
*
|
||||||
|
@ -237,6 +238,14 @@ declare namespace Deno {
|
||||||
* | macOS | – | – |
|
* | macOS | – | – |
|
||||||
* | Windows | `{FOLDERID_Templates}` | C:\Users\Alice\AppData\Roaming\Microsoft\Windows\Templates |
|
* | 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"`
|
* `"video"`
|
||||||
*
|
*
|
||||||
* |Platform | Value | Example |
|
* |Platform | Value | Example |
|
||||||
|
|
|
@ -88,6 +88,7 @@ type DirKind =
|
||||||
| "picture"
|
| "picture"
|
||||||
| "public"
|
| "public"
|
||||||
| "template"
|
| "template"
|
||||||
|
| "tmp"
|
||||||
| "video";
|
| "video";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -191,6 +192,14 @@ type DirKind =
|
||||||
* | macOS | – | – |
|
* | macOS | – | – |
|
||||||
* | Windows | `{FOLDERID_Templates}` | C:\Users\Alice\AppData\Roaming\Microsoft\Windows\Templates |
|
* | 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"
|
* "video"
|
||||||
* |Platform | Value | Example |
|
* |Platform | Value | Example |
|
||||||
* | ------- | ------------------- | --------------------- |
|
* | ------- | ------------------- | --------------------- |
|
||||||
|
|
|
@ -234,6 +234,14 @@ testPerm({ env: true }, function getDir(): void {
|
||||||
{ os: "linux", shouldHaveValue: false }
|
{ os: "linux", shouldHaveValue: false }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
kind: "tmp",
|
||||||
|
runtime: [
|
||||||
|
{ os: "mac", shouldHaveValue: true },
|
||||||
|
{ os: "win", shouldHaveValue: true },
|
||||||
|
{ os: "linux", shouldHaveValue: true }
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
kind: "video",
|
kind: "video",
|
||||||
runtime: [
|
runtime: [
|
||||||
|
|
|
@ -49,6 +49,7 @@ fn op_get_dir(
|
||||||
"picture" => dirs::picture_dir(),
|
"picture" => dirs::picture_dir(),
|
||||||
"public" => dirs::public_dir(),
|
"public" => dirs::public_dir(),
|
||||||
"template" => dirs::template_dir(),
|
"template" => dirs::template_dir(),
|
||||||
|
"tmp" => Some(std::env::temp_dir()),
|
||||||
"video" => dirs::video_dir(),
|
"video" => dirs::video_dir(),
|
||||||
_ => {
|
_ => {
|
||||||
return Err(
|
return Err(
|
||||||
|
|
|
@ -180,9 +180,9 @@ export function setPriority(pid: number, priority?: number): void {
|
||||||
notImplemented(SEE_GITHUB_ISSUE);
|
notImplemented(SEE_GITHUB_ISSUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Not yet implemented */
|
/** Returns the operating system's default directory for temporary files as a string. */
|
||||||
export function tmpdir(): string {
|
export function tmpdir(): string | null {
|
||||||
notImplemented(SEE_GITHUB_ISSUE);
|
return Deno.dir("tmp");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Not yet implemented */
|
/** Not yet implemented */
|
||||||
|
|
|
@ -16,6 +16,13 @@ test({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test({
|
||||||
|
name: "tmp directory is a string",
|
||||||
|
fn() {
|
||||||
|
assertEquals(typeof os.tmpdir(), "string");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
test({
|
test({
|
||||||
name: "hostname is a string",
|
name: "hostname is a string",
|
||||||
fn() {
|
fn() {
|
||||||
|
@ -230,13 +237,6 @@ test({
|
||||||
Error,
|
Error,
|
||||||
"Not implemented"
|
"Not implemented"
|
||||||
);
|
);
|
||||||
assertThrows(
|
|
||||||
() => {
|
|
||||||
os.tmpdir();
|
|
||||||
},
|
|
||||||
Error,
|
|
||||||
"Not implemented"
|
|
||||||
);
|
|
||||||
assertThrows(
|
assertThrows(
|
||||||
() => {
|
() => {
|
||||||
os.totalmem();
|
os.totalmem();
|
||||||
|
|
Loading…
Reference in a new issue