From 9f7586a20691e5adb080f60f569498844f8a295f Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Tue, 2 Jan 2024 19:27:54 +0530 Subject: [PATCH] fix(ext/node): implement os.machine (#21751) --- cli/tests/unit_node/os_test.ts | 11 +++++++++++ ext/node/polyfills/os.ts | 12 ++++++++++++ 2 files changed, 23 insertions(+) diff --git a/cli/tests/unit_node/os_test.ts b/cli/tests/unit_node/os_test.ts index 4df53534ae..f4da8d030f 100644 --- a/cli/tests/unit_node/os_test.ts +++ b/cli/tests/unit_node/os_test.ts @@ -29,6 +29,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() { diff --git a/ext/node/polyfills/os.ts b/ext/node/polyfills/os.ts index 83e56e9f4b..af3e69d64a 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,