Skip to content

Commit 4054642

Browse files
dahliacodex
andcommitted
Use vocab-runtime jsonld subpath
Move the jsonld ESM shim into @fedify/vocab-runtime and expose it through the new jsonld subpath export. This avoids fragile relative imports in generated vocab sources while keeping JSR-safe packaging for the deep jsonld ESM entrypoint. Update Fedify's Linked Data signature code, the vocab code generator, snapshots, and CHANGES.md to use the shared runtime module. #639 (comment) Co-Authored-By: OpenAI Codex <codex@openai.com>
1 parent b894fbc commit 4054642

20 files changed

Lines changed: 75 additions & 31 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
.pnpm-store/
44
.vocab-codegen.lock/
55
dist/
6+
dist-tests/
67
node_modules/
78
package-lock.json
89
repomix-output.xml

CHANGES.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ To be released.
1010

1111
### @fedify/fedify
1212

13-
- Switched Fedify's JSR-facing JSON-LD imports to jsonld's ESM entrypoint
14-
so source-based runtimes such as Deno, Cloudflare Workers, and Fresh 2's
15-
Vite SSR pipeline do not have to evaluate the package through CommonJS
16-
interop when loading Linked Data signature support. Fresh 2 development
17-
mode has been verified on Deno 2.7.7 after an upstream Deno 2.7.6 dev
18-
server regression was fixed. [[#621], [#639]]
13+
- Switched Fedify's source-based JSON-LD loading to the new
14+
`@fedify/vocab-runtime/jsonld` subpath so generated vocabulary code and
15+
Linked Data signature support no longer have to evaluate `jsonld` through
16+
a CommonJS-sensitive package root in Fresh 2, Deno, and other ESM-first
17+
runtimes. Fresh 2 development mode has been verified on Deno 2.7.7
18+
after an upstream Deno 2.7.6 dev server regression was fixed.
19+
[[#621], [#639]]
1920

2021
[#621]: https://github.com/fedify-dev/fedify/issues/621
2122
[#639]: https://github.com/fedify-dev/fedify/pull/639
@@ -28,6 +29,11 @@ To be released.
2829
`TypeError: varint.encode is not a function`. Fresh 2 no longer needs a
2930
Vite externalization workaround for Fedify. [[#621], [#639]]
3031

32+
- Added the new `@fedify/vocab-runtime/jsonld` subpath export so generated
33+
vocabulary code and other Fedify runtime code can share a JSR-safe wrapper
34+
around `jsonld`'s ESM entrypoint instead of depending on fragile relative
35+
shims or the package-root import path. [[#621], [#639]]
36+
3137
### @fedify/init
3238

3339
- Revived removed `fedify init` options. [[#632], [#638] by ChanHaeng Lee]

deno.lock

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/fedify/src/sig/ld.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { Activity, CryptographicKey, getTypeId, Object } from "@fedify/vocab";
22
import { type DocumentLoader, getDocumentLoader } from "@fedify/vocab-runtime";
3+
import jsonld from "@fedify/vocab-runtime/jsonld";
34
import { getLogger } from "@logtape/logtape";
45
import { SpanStatusCode, trace, type TracerProvider } from "@opentelemetry/api";
56
import { decodeBase64, encodeBase64 } from "byte-encodings/base64";
67
import { encodeHex } from "byte-encodings/hex";
7-
// @ts-ignore TS7016
8-
import jsonld from "jsonld/dist/jsonld.esm.js";
98
import metadata from "../../deno.json" with { type: "json" };
109
import { fetchKey, type KeyCache, validateCryptoKey } from "./key.ts";
1110

packages/fixture/deno.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
},
88
"exclude": [
99
"dist",
10+
"dist-tests",
1011
"node_modules"
1112
],
1213
"tasks": {

packages/fixture/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"prepack": "pnpm build",
5050
"prepublish": "pnpm build",
5151
"pretest": "pnpm build",
52-
"test": "cd dist/ && node --test"
52+
"test": "cd dist-tests && node --test"
5353
},
5454
"private": true
5555
}

packages/fixture/tsdown.config.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1-
import { cp, glob } from "node:fs/promises";
2-
import { join, sep } from "node:path";
1+
import { glob, mkdir, readFile, writeFile } from "node:fs/promises";
2+
import { dirname, join, sep } from "node:path";
33
import { defineConfig } from "tsdown";
44

5+
async function copyFileSafely(
6+
source: string,
7+
destination: string,
8+
): Promise<void> {
9+
await mkdir(dirname(destination), { recursive: true });
10+
await writeFile(destination, await readFile(source));
11+
}
12+
513
export default [
614
defineConfig({
715
entry: ["src/mod.ts"],
@@ -12,18 +20,19 @@ export default [
1220
hooks: {
1321
"build:done": async (ctx) => {
1422
for await (const file of glob("src/fixtures/**/*.json")) {
15-
await cp(
23+
await copyFileSafely(
1624
file,
1725
join(ctx.options.outDir, file.replace(`src${sep}`, "")),
18-
{ force: true },
1926
);
2027
}
2128
},
2229
},
2330
}),
2431
defineConfig({
32+
outDir: "dist-tests",
2533
entry: (await Array.fromAsync(glob(`src/**/*.test.ts`)))
2634
.map((f) => f.replace(sep, "/")),
35+
dts: false,
2736
format: ["esm", "cjs"],
2837
platform: "node",
2938
external: [

packages/vocab-runtime/deno.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"version": "2.0.7",
44
"license": "MIT",
55
"exports": {
6-
".": "./src/mod.ts"
6+
".": "./src/mod.ts",
7+
"./jsonld": "./src/jsonld.ts"
78
},
89
"description": "Runtime library for @fedify/vocab",
910
"author": {
@@ -16,6 +17,7 @@
1617
"asn1js": "npm:asn1js@^3.0.6",
1718
"byte-encodings": "npm:byte-encodings@^1.0.11",
1819
"fetch-mock": "npm:fetch-mock@^12.5.4",
20+
"jsonld": "npm:jsonld@^9.0.0",
1921
"pkijs": "npm:pkijs@^3.2.5"
2022
},
2123
"exclude": [

packages/vocab-runtime/package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@
3535
"require": "./dist/mod.cjs",
3636
"default": "./dist/mod.js"
3737
},
38+
"./jsonld": {
39+
"types": {
40+
"import": "./dist/jsonld.d.ts",
41+
"require": "./dist/jsonld.d.cts",
42+
"default": "./dist/jsonld.d.ts"
43+
},
44+
"import": "./dist/jsonld.js",
45+
"require": "./dist/jsonld.cjs",
46+
"default": "./dist/jsonld.js"
47+
},
3848
"./package.json": "./package.json"
3949
},
4050
"scripts": {
@@ -68,6 +78,7 @@
6878
"@opentelemetry/api": "catalog:",
6979
"asn1js": "catalog:",
7080
"byte-encodings": "catalog:",
81+
"jsonld": "^9.0.0",
7182
"pkijs": "catalog:"
7283
}
7384
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// @ts-ignore TS7016
2+
import jsonld from "jsonld/dist/jsonld.esm.js";
3+
4+
export default jsonld as typeof import("jsonld");

0 commit comments

Comments
 (0)