Unverified Commit f0a81ada authored by Hong Minhee's avatar Hong Minhee
Browse files

Fix `getUserAgent()` 2 return correct runtime name

parent 9db691cb
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -8,6 +8,11 @@ Version 1.3.6

To be released.

 -  Fixed a bug where `getUserAgent()` function had returned a `User-Agent`
    string with a wrong JavaScript runtime name on Node.js.  [[#203]]

[#203]: https://github.com/fedify-dev/fedify/issues/203


Version 1.3.5
-------------
+1 −1
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@
  },
  "imports": {
    "@cfworker/json-schema": "npm:@cfworker/json-schema@^2.0.1",
    "@david/which-runtime": "jsr:@david/which-runtime@^0.2.0",
    "@david/which-runtime": "jsr:@david/which-runtime@^0.2.1",
    "@deno/dnt": "jsr:@deno/dnt@0.41.2",
    "@fedify/fedify": "./mod.ts",
    "@fedify/fedify/federation": "./federation/mod.ts",
+2 −1
Original line number Diff line number Diff line
import { isDeno } from "@david/which-runtime";
import { assertEquals, assertRejects, assertThrows } from "@std/assert";
import * as mf from "mock_fetch";
import process from "node:process";
@@ -550,7 +551,7 @@ test("kvCache()", async (t) => {
});

test("getUserAgent()", () => {
  if ("Deno" in globalThis) {
  if (isDeno) {
    assertEquals(
      getUserAgent(),
      `Fedify/${metadata.version} (Deno/${Deno.version.deno})`,
+3 −4
Original line number Diff line number Diff line
import { isDeno, isNode } from "@david/which-runtime";
import { HTTPHeaderLink } from "@hugoalh/http-header-link";
import { getLogger } from "@logtape/logtape";
import process from "node:process";
@@ -520,12 +521,10 @@ export function getUserAgent(
  { software, url }: GetUserAgentOptions = {},
): string {
  const fedify = `Fedify/${metadata.version}`;
  const runtime = "Deno" in globalThis
    ? `Deno/${Deno.version.deno}`
    : "Bun" in globalThis
  const runtime = isDeno ? `Deno/${Deno.version.deno}` : "Bun" in globalThis
    // @ts-ignore: `Bun` is a global variable in Bun
    ? `Bun/${Bun.version}`
    : "process" in globalThis
    : isNode
    ? `Node.js/${process.version}`
    : null;
  const userAgent = software == null ? [fedify] : [software, fedify];