mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 12:19:12 +00:00
Add missing node os.release() implementation (#4065)
This commit is contained in:
parent
fe9ac35a65
commit
fb08cf7005
8 changed files with 66 additions and 11 deletions
|
@ -85,7 +85,16 @@ export {
|
||||||
ShutdownMode,
|
ShutdownMode,
|
||||||
shutdown
|
shutdown
|
||||||
} from "./net.ts";
|
} from "./net.ts";
|
||||||
export { dir, env, exit, isTTY, execPath, hostname, loadavg } from "./os.ts";
|
export {
|
||||||
|
dir,
|
||||||
|
env,
|
||||||
|
exit,
|
||||||
|
isTTY,
|
||||||
|
execPath,
|
||||||
|
hostname,
|
||||||
|
loadavg,
|
||||||
|
osRelease
|
||||||
|
} from "./os.ts";
|
||||||
export {
|
export {
|
||||||
permissions,
|
permissions,
|
||||||
PermissionName,
|
PermissionName,
|
||||||
|
|
|
@ -81,6 +81,7 @@ export let OP_SIGNAL_BIND: number;
|
||||||
export let OP_SIGNAL_UNBIND: number;
|
export let OP_SIGNAL_UNBIND: number;
|
||||||
export let OP_SIGNAL_POLL: number;
|
export let OP_SIGNAL_POLL: number;
|
||||||
export let OP_LOADAVG: number;
|
export let OP_LOADAVG: number;
|
||||||
|
export let OP_OS_RELEASE: number;
|
||||||
|
|
||||||
const PLUGIN_ASYNC_HANDLER_MAP: Map<number, AsyncHandler> = new Map();
|
const PLUGIN_ASYNC_HANDLER_MAP: Map<number, AsyncHandler> = new Map();
|
||||||
|
|
||||||
|
|
6
cli/js/lib.deno.ns.d.ts
vendored
6
cli/js/lib.deno.ns.d.ts
vendored
|
@ -52,6 +52,12 @@ declare namespace Deno {
|
||||||
*/
|
*/
|
||||||
export function hostname(): string;
|
export function hostname(): string;
|
||||||
|
|
||||||
|
/** Get the OS release. Requires the `--allow-env` flag.
|
||||||
|
*
|
||||||
|
* console.log(Deno.osRelease());
|
||||||
|
*/
|
||||||
|
export function osRelease(): string;
|
||||||
|
|
||||||
/** Exit the Deno process with optional exit code. */
|
/** Exit the Deno process with optional exit code. */
|
||||||
export function exit(code?: number): never;
|
export function exit(code?: number): never;
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,15 @@ export function hostname(): string {
|
||||||
return sendSync(dispatch.OP_HOSTNAME);
|
return sendSync(dispatch.OP_HOSTNAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Get OS release.
|
||||||
|
* Requires the `--allow-env` flag.
|
||||||
|
*
|
||||||
|
* console.log(Deno.osRelease());
|
||||||
|
*/
|
||||||
|
export function osRelease(): string {
|
||||||
|
return sendSync(dispatch.OP_OS_RELEASE);
|
||||||
|
}
|
||||||
|
|
||||||
/** Exit the Deno process with optional exit code. */
|
/** Exit the Deno process with optional exit code. */
|
||||||
export function exit(code = 0): never {
|
export function exit(code = 0): never {
|
||||||
sendSync(dispatch.OP_EXIT, { code });
|
sendSync(dispatch.OP_EXIT, { code });
|
||||||
|
|
|
@ -315,3 +315,19 @@ testPerm({ env: false }, function hostnamePerm(): void {
|
||||||
}
|
}
|
||||||
assert(caughtError);
|
assert(caughtError);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testPerm({ env: true }, function releaseDir(): void {
|
||||||
|
assertNotEquals(Deno.osRelease(), "");
|
||||||
|
});
|
||||||
|
|
||||||
|
testPerm({ env: false }, function releasePerm(): void {
|
||||||
|
let caughtError = false;
|
||||||
|
try {
|
||||||
|
Deno.osRelease();
|
||||||
|
} catch (err) {
|
||||||
|
caughtError = true;
|
||||||
|
assert(err instanceof Deno.Err.PermissionDenied);
|
||||||
|
assertEquals(err.name, "PermissionDenied");
|
||||||
|
}
|
||||||
|
assert(caughtError);
|
||||||
|
});
|
||||||
|
|
|
@ -21,6 +21,10 @@ pub fn init(i: &mut Isolate, s: &State) {
|
||||||
i.register_op("get_dir", s.core_op(json_op(s.stateful_op(op_get_dir))));
|
i.register_op("get_dir", s.core_op(json_op(s.stateful_op(op_get_dir))));
|
||||||
i.register_op("hostname", s.core_op(json_op(s.stateful_op(op_hostname))));
|
i.register_op("hostname", s.core_op(json_op(s.stateful_op(op_hostname))));
|
||||||
i.register_op("loadavg", s.core_op(json_op(s.stateful_op(op_loadavg))));
|
i.register_op("loadavg", s.core_op(json_op(s.stateful_op(op_loadavg))));
|
||||||
|
i.register_op(
|
||||||
|
"os_release",
|
||||||
|
s.core_op(json_op(s.stateful_op(op_os_release))),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
@ -185,6 +189,16 @@ fn op_hostname(
|
||||||
_zero_copy: Option<ZeroCopyBuf>,
|
_zero_copy: Option<ZeroCopyBuf>,
|
||||||
) -> Result<JsonOp, OpError> {
|
) -> Result<JsonOp, OpError> {
|
||||||
state.check_env()?;
|
state.check_env()?;
|
||||||
let hostname = sys_info::hostname().unwrap_or_else(|_| "".to_owned());
|
let hostname = sys_info::hostname().unwrap_or_else(|_| "".to_string());
|
||||||
Ok(JsonOp::Sync(json!(hostname)))
|
Ok(JsonOp::Sync(json!(hostname)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn op_os_release(
|
||||||
|
state: &State,
|
||||||
|
_args: Value,
|
||||||
|
_zero_copy: Option<ZeroCopyBuf>,
|
||||||
|
) -> Result<JsonOp, OpError> {
|
||||||
|
state.check_env()?;
|
||||||
|
let release = sys_info::os_release().unwrap_or_else(|_| "".to_string());
|
||||||
|
Ok(JsonOp::Sync(json!(release)))
|
||||||
|
}
|
||||||
|
|
|
@ -161,9 +161,9 @@ export function platform(): string {
|
||||||
return process.platform;
|
return process.platform;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Not yet implemented */
|
/** Returns the operating system as a string */
|
||||||
export function release(): string {
|
export function release(): string {
|
||||||
notImplemented(SEE_GITHUB_ISSUE);
|
return Deno.osRelease();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Not yet implemented */
|
/** Not yet implemented */
|
||||||
|
|
|
@ -30,6 +30,13 @@ test({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test({
|
||||||
|
name: "release is a string",
|
||||||
|
fn() {
|
||||||
|
assertEquals(typeof os.release(), "string");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
test({
|
test({
|
||||||
name: "getPriority(): PID must be a 32 bit integer",
|
name: "getPriority(): PID must be a 32 bit integer",
|
||||||
fn() {
|
fn() {
|
||||||
|
@ -216,13 +223,6 @@ test({
|
||||||
Error,
|
Error,
|
||||||
"Not implemented"
|
"Not implemented"
|
||||||
);
|
);
|
||||||
assertThrows(
|
|
||||||
() => {
|
|
||||||
os.release();
|
|
||||||
},
|
|
||||||
Error,
|
|
||||||
"Not implemented"
|
|
||||||
);
|
|
||||||
assertThrows(
|
assertThrows(
|
||||||
() => {
|
() => {
|
||||||
os.setPriority(0);
|
os.setPriority(0);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue