diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2024-01-02 19:27:54 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-02 14:57:54 +0100 |
commit | 9f7586a20691e5adb080f60f569498844f8a295f (patch) | |
tree | 0b256481c33216b2a42a94693d6a8c44aa97cead | |
parent | 8e4feacd258b2fc019f2b9612133231fa8be14c0 (diff) |
fix(ext/node): implement os.machine (#21751)
-rw-r--r-- | cli/tests/unit_node/os_test.ts | 11 | ||||
-rw-r--r-- | ext/node/polyfills/os.ts | 12 |
2 files changed, 23 insertions, 0 deletions
diff --git a/cli/tests/unit_node/os_test.ts b/cli/tests/unit_node/os_test.ts index 4df53534a..f4da8d030 100644 --- a/cli/tests/unit_node/os_test.ts +++ b/cli/tests/unit_node/os_test.ts @@ -30,6 +30,17 @@ Deno.test({ }); Deno.test({ + name: "os machine (arch)", + fn() { + if (Deno.build.arch == "aarch64") { + assertEquals(os.machine(), "arm64"); + } else { + assertEquals(os.machine(), Deno.build.arch); + } + }, +}); + +Deno.test({ name: "home directory is a string", fn() { assertEquals(typeof os.homedir(), "string"); diff --git a/ext/node/polyfills/os.ts b/ext/node/polyfills/os.ts index 83e56e9f4..af3e69d64 100644 --- a/ext/node/polyfills/os.ts +++ b/ext/node/polyfills/os.ts @@ -129,6 +129,8 @@ export function arch(): string { (type as any)[Symbol.toPrimitive] = (): string => type(); // deno-lint-ignore no-explicit-any (uptime as any)[Symbol.toPrimitive] = (): number => uptime(); +// deno-lint-ignore no-explicit-any +(machine as any)[Symbol.toPrimitive] = (): string => machine(); export function cpus(): CPUCoreInfo[] { return ops.op_cpus(); @@ -247,6 +249,15 @@ export function version(): string { return Deno.osRelease(); } +/** Returns the machine type as a string */ +export function machine(): string { + if (Deno.build.arch == "aarch64") { + return "arm64"; + } + + return Deno.build.arch; +} + /** Not yet implemented */ export function setPriority(pid: number, priority?: number) { /* The node API has the 'pid' as the first parameter and as optional. @@ -373,6 +384,7 @@ export default { hostname, loadavg, networkInterfaces, + machine, platform, release, setPriority, |