From c02a232ca65ea822ca4c656e49e7f4b919dd2b26 Mon Sep 17 00:00:00 2001 From: Hexagon Date: Tue, 4 Jun 2024 21:50:42 +0200 Subject: [PATCH] Dependency update. Remove sysinfo-module. --- deno.json | 4 +- docs/src/changelog.md | 1 + .../src/examples/basic-webinterface/pup.jsonc | 2 +- lib/common/sysinfo.ts | 79 ------------------- lib/core/status.ts | 2 +- 5 files changed, 5 insertions(+), 83 deletions(-) delete mode 100644 lib/common/sysinfo.ts diff --git a/deno.json b/deno.json index 6d06eb9..febf147 100644 --- a/deno.json +++ b/deno.json @@ -38,11 +38,11 @@ "@cross/env": "jsr:@cross/env@~1.0.2", "@cross/fs": "jsr:@cross/fs@~0.1.11", "@cross/jwt": "jsr:@cross/jwt@~0.4.7", - "@cross/kv": "jsr:@cross/kv@^0.15.6", + "@cross/kv": "jsr:@cross/kv@^0.15.8", "@cross/runtime": "jsr:@cross/runtime@~1.0.0", "@cross/service": "jsr:@cross/service@~1.0.3", "@cross/test": "jsr:@cross/test@~0.0.9", - "@cross/utils": "jsr:@cross/utils@~0.12.0", + "@cross/utils": "jsr:@cross/utils@~0.13.0", "@hexagon/croner": "jsr:@hexagon/croner@~8.0.2", "@oak/oak": "jsr:@oak/oak@~16.0.0", "@pup/api-client": "jsr:@pup/api-client@~2.0.0", diff --git a/docs/src/changelog.md b/docs/src/changelog.md index 253a4a2..d9a6b28 100644 --- a/docs/src/changelog.md +++ b/docs/src/changelog.md @@ -13,6 +13,7 @@ All notable changes to this project will be documented in this section. - fix(core): Replace `Deno.Kv` with `@cross/kv` for cross-runtime compatibility, more compact logs and avoiding `--unstable` - fix(core): Internal changes to support Node and Bun +- fix(core): Removes the `sysinfo.ts`-module in favor of `@cross/utils/sysinfo` ## [1.0.0-rc.39] - 2024-05-04 diff --git a/docs/src/examples/basic-webinterface/pup.jsonc b/docs/src/examples/basic-webinterface/pup.jsonc index a77e925..6fab97a 100644 --- a/docs/src/examples/basic-webinterface/pup.jsonc +++ b/docs/src/examples/basic-webinterface/pup.jsonc @@ -50,7 +50,7 @@ "plugins": [ { // Use full uri to plugin, e.g. jsr:@pup/plugin-web-interface - "url": "jsr:@pup/plugin-web-interface@^2.0.2", + "url": "jsr:@pup/plugin-web-interface", "options": { "port": 8002 } diff --git a/lib/common/sysinfo.ts b/lib/common/sysinfo.ts deleted file mode 100644 index f4b4968..0000000 --- a/lib/common/sysinfo.ts +++ /dev/null @@ -1,79 +0,0 @@ -import { CurrentRuntime, Runtime } from "@cross/runtime" -import { ApiMemoryUsage, ApiSystemMemory } from "@pup/api-definitions" -import { freemem, loadavg, totalmem, uptime as nodeUptime } from "node:os" - -export function memoryUsage(): ApiMemoryUsage { - let memoryUsageResult: ApiMemoryUsage - if (CurrentRuntime === Runtime.Deno) { - //@ts-ignore cross-runtime - const { external, heapTotal, heapUsed, rss } = Deno.memoryUsage() - memoryUsageResult = { external, heapTotal, heapUsed, rss } - } else if ( - CurrentRuntime === Runtime.Node || CurrentRuntime === Runtime.Bun - ) { - //@ts-ignore cross-runtime - const { external = 0, heapTotal, heapUsed, rss } = process.memoryUsage() - memoryUsageResult = { external, heapTotal, heapUsed, rss } - } else { - memoryUsageResult = { external: 0, heapTotal: 0, heapUsed: 0, rss: 0 } - } - return memoryUsageResult -} - -export function loadAvg(): number[] { - let loadAvgResult: number[] - if (CurrentRuntime === Runtime.Deno) { - loadAvgResult = Deno.loadavg() - } else if (CurrentRuntime === Runtime.Node || CurrentRuntime === Runtime.Bun) { - // Node.js and Bun provide os module for loadAvg - loadAvgResult = loadavg() - } else { - // Unsupported runtime - loadAvgResult = [] - } - return loadAvgResult -} - -export function uptime(): number { - let uptimeResult: number - if (CurrentRuntime === Runtime.Deno) { - uptimeResult = Deno.osUptime() - } else if (CurrentRuntime === Runtime.Node || CurrentRuntime === Runtime.Bun) { - // Node.js and Bun provide os module for uptime - uptimeResult = nodeUptime() - } else { - uptimeResult = -1 - } - return uptimeResult -} - -export function systemMemoryInfo(): ApiSystemMemory { - let memoryInfoResult: ApiSystemMemory - if (CurrentRuntime === Runtime.Deno) { - memoryInfoResult = Deno.systemMemoryInfo() - } else if (CurrentRuntime === Runtime.Node || CurrentRuntime === Runtime.Bun) { - // Node.js and Bun don't have a direct equivalent to Deno.systemMemoryInfo - // We can try to approximate values using os module (limited information) - memoryInfoResult = { - total: totalmem(), - free: freemem(), - available: -1, // Not directly available - buffers: -1, // Not directly available - cached: -1, // Not directly available - swapTotal: -1, // Approximate swap total - swapFree: -1, // Not directly available - } - } else { - // Unsupported runtime - memoryInfoResult = { - total: -1, - free: -1, - available: -1, - buffers: -1, - cached: -1, - swapTotal: -1, - swapFree: -1, - } - } - return memoryInfoResult -} diff --git a/lib/core/status.ts b/lib/core/status.ts index a8c7b89..274340a 100644 --- a/lib/core/status.ts +++ b/lib/core/status.ts @@ -12,7 +12,7 @@ import { ApiApplicationState, ApiProcessState } from "@pup/api-definitions" import { KV } from "@cross/kv" import { Prop } from "../common/prop.ts" -import { loadAvg, memoryUsage, systemMemoryInfo, uptime } from "../common/sysinfo.ts" +import { loadAvg, memoryUsage, systemMemoryInfo, uptime } from "@cross/utils/sysinfo" import { getCurrentOS, getCurrentRuntime, getCurrentVersion } from "@cross/runtime" import { pid } from "@cross/utils"