Skip to content

Commit a0a1961

Browse files
committed
Remove dependency on @david/which-runtime
1 parent c6932db commit a0a1961

4 files changed

Lines changed: 25 additions & 18 deletions

File tree

fedify/deno.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
},
1919
"imports": {
2020
"@cfworker/json-schema": "npm:@cfworker/json-schema@^2.0.1",
21-
"@david/which-runtime": "jsr:@david/which-runtime@^0.2.1",
2221
"@deno/dnt": "jsr:@deno/dnt@0.41.3",
2322
"@es-toolkit/es-toolkit": "jsr:@es-toolkit/es-toolkit@^1.38.0",
2423
"@hugoalh/http-header-link": "jsr:@hugoalh/http-header-link@^1.0.2",

fedify/runtime/docloader.test.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { isDeno } from "@david/which-runtime";
21
import { assertEquals, assertRejects, assertThrows } from "@std/assert";
32
import * as mf from "mock_fetch";
43
import process from "node:process";
@@ -595,7 +594,8 @@ test("kvCache()", async (t) => {
595594
});
596595

597596
test("getUserAgent()", () => {
598-
if (isDeno) {
597+
// dnt-shim-ignore
598+
if ("Deno" in globalThis) {
599599
assertEquals(
600600
getUserAgent(),
601601
`Fedify/${metadata.version} (Deno/${Deno.version.deno})`,
@@ -615,7 +615,8 @@ test("getUserAgent()", () => {
615615
}),
616616
`MyApp/1.0.0 (Fedify/${metadata.version}; Deno/${Deno.version.deno}; +https://example.com/)`,
617617
);
618-
} else if ("Bun" in globalThis) {
618+
} // dnt-shim-ignore
619+
else if ("Bun" in globalThis) {
619620
assertEquals(
620621
getUserAgent(),
621622
// @ts-ignore: `Bun` is a global variable in Bun
@@ -642,22 +643,22 @@ test("getUserAgent()", () => {
642643
} else {
643644
assertEquals(
644645
getUserAgent(),
645-
`Fedify/${metadata.version} (Node.js/${process.version})`,
646+
`Fedify/${metadata.version} (Node.js/${process.versions.node})`,
646647
);
647648
assertEquals(
648649
getUserAgent({ software: "MyApp/1.0.0" }),
649-
`MyApp/1.0.0 (Fedify/${metadata.version}; Node.js/${process.version})`,
650+
`MyApp/1.0.0 (Fedify/${metadata.version}; Node.js/${process.versions.node})`,
650651
);
651652
assertEquals(
652653
getUserAgent({ url: "https://example.com/" }),
653-
`Fedify/${metadata.version} (Node.js/${process.version}; +https://example.com/)`,
654+
`Fedify/${metadata.version} (Node.js/${process.versions.node}; +https://example.com/)`,
654655
);
655656
assertEquals(
656657
getUserAgent({
657658
software: "MyApp/1.0.0",
658659
url: new URL("https://example.com/"),
659660
}),
660-
`MyApp/1.0.0 (Fedify/${metadata.version}; Node.js/${process.version}; +https://example.com/)`,
661+
`MyApp/1.0.0 (Fedify/${metadata.version}; Node.js/${process.versions.node}; +https://example.com/)`,
661662
);
662663
}
663664
});

fedify/runtime/docloader.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { isDeno, isNode } from "@david/which-runtime";
21
import { HTTPHeaderLink } from "@hugoalh/http-header-link";
32
import { getLogger } from "@logtape/logtape";
43
import type { TracerProvider } from "@opentelemetry/api";
@@ -558,12 +557,19 @@ export function getUserAgent(
558557
{ software, url }: GetUserAgentOptions = {},
559558
): string {
560559
const fedify = `Fedify/${metadata.version}`;
561-
const runtime = isDeno ? `Deno/${Deno.version.deno}` : "Bun" in globalThis
562-
// @ts-ignore: `Bun` is a global variable in Bun
563-
? `Bun/${Bun.version}`
564-
: isNode
565-
? `Node.js/${process.version}`
566-
: null;
560+
const runtime = // dnt-shim-ignore
561+
// deno-lint-ignore no-explicit-any
562+
(globalThis as any).Deno?.version?.deno != null
563+
? `Deno/${Deno.version.deno}`
564+
// dnt-shim-ignore
565+
// deno-lint-ignore no-explicit-any
566+
: (globalThis as any).process?.versions?.bun != null
567+
? `Bun/${process.versions.bun}`
568+
// dnt-shim-ignore
569+
// deno-lint-ignore no-explicit-any
570+
: (globalThis as any).process?.versions?.node != null
571+
? `Node.js/${process.versions.node}`
572+
: null;
567573
const userAgent = software == null ? [fedify] : [software, fedify];
568574
if (runtime != null) userAgent.push(runtime);
569575
if (url != null) userAgent.push(`+${url.toString()}`);

fedify/vocab/vocab.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { isDeno } from "@david/which-runtime";
21
import { pascalCase } from "@es-toolkit/es-toolkit";
32
import { parseLanguageTag } from "@phensley/language-tag";
43
import {
@@ -517,7 +516,8 @@ test("Deno.inspect(Object)", () => {
517516
});
518517
assertEquals(
519518
Deno.inspect(obj, { colors: false, sorted: true, compact: false }),
520-
isDeno
519+
// dnt-shim-ignore
520+
"Deno" in globalThis
521521
? "Object {\n" +
522522
' attribution: URL "https://example.com/foo",\n' +
523523
" contents: [\n" +
@@ -1249,7 +1249,8 @@ for (const typeUri in types) {
12491249
);
12501250
});
12511251

1252-
if (isDeno) {
1252+
// dnt-shim-ignore
1253+
if ("Deno" in globalThis) {
12531254
test(`Deno.inspect(${type.name}) [auto]`, async (t) => {
12541255
const empty = new cls({});
12551256
assertEquals(Deno.inspect(empty), `${type.name} {}`);

0 commit comments

Comments
 (0)