Skip to content

Commit 8f74f40

Browse files
committed
Fix Astro npm entrypoints
Restore the published npm entrypoint contract for @fedify/astro by making tsdown emit dist/*.js and dist/*.d.ts files that match the package metadata again. Add a self-reference regression test that exercises the public API through ESM import and CommonJS require so the packaged entrypoints are validated the way consumers load them. Update CHANGES.md with the packaging fix details. Fixes #699 Assisted-by: Codex:gpt-5.4
1 parent 9623273 commit 8f74f40

4 files changed

Lines changed: 123 additions & 0 deletions

File tree

CHANGES.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ Version 2.1.6
88

99
To be released.
1010

11+
### @fedify/astro
12+
13+
- Restored the npm entrypoint contract for `@fedify/astro` by making the
14+
build emit _dist/\*.js_ and _dist/\*.d.ts_ files that match the published
15+
package metadata again. This fixes package resolution failures caused by
16+
_package.json_ exporting files that did not exist in the npm tarball.
17+
[[#699]]
18+
19+
[#699]: https://github.com/fedify-dev/fedify/issues/699
20+
1121
### @fedify/cli
1222

1323
- Fixed `fedify lookup` failing to look up URLs on private or localhost

packages/astro/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"build": "pnpm --filter @fedify/astro... run build:self",
6262
"prepack": "pnpm build",
6363
"prepublish": "pnpm build",
64+
"pretest": "pnpm build",
6465
"test": "node --experimental-transform-types --test"
6566
}
6667
}

packages/astro/src/package.test.ts

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import { deepStrictEqual, strictEqual } from "node:assert/strict";
2+
import { createRequire } from "node:module";
3+
import test from "node:test";
4+
5+
const require = createRequire(import.meta.url);
6+
7+
function expectResponse(response: void | Response): Response {
8+
if (!(response instanceof Response)) {
9+
throw new TypeError("Expected middleware to return a Response");
10+
}
11+
return response;
12+
}
13+
14+
test("self-reference ESM import exposes working Astro integration API", async () => {
15+
const mod = await import("@fedify/astro");
16+
17+
strictEqual(typeof mod.fedifyIntegration, "function");
18+
strictEqual(typeof mod.fedifyMiddleware, "function");
19+
20+
const integration = mod.fedifyIntegration();
21+
strictEqual(integration.name, "@fedify/astro");
22+
23+
let capturedConfig: unknown;
24+
(
25+
integration.hooks as Record<
26+
"astro:config:setup",
27+
(args: { updateConfig(config: unknown): void }) => void
28+
>
29+
)["astro:config:setup"]({
30+
updateConfig(config) {
31+
capturedConfig = config;
32+
},
33+
});
34+
deepStrictEqual(capturedConfig, {
35+
vite: {
36+
ssr: {
37+
noExternal: ["@fedify/fedify", "@fedify/vocab"],
38+
},
39+
},
40+
});
41+
42+
let capturedRequest: Request | undefined;
43+
let capturedContextData: unknown;
44+
const middleware = mod.fedifyMiddleware(
45+
{
46+
fetch(
47+
request: Request,
48+
options: {
49+
contextData: string;
50+
onNotAcceptable(request: Request): Promise<Response>;
51+
},
52+
) {
53+
capturedRequest = request;
54+
capturedContextData = options.contextData;
55+
return options.onNotAcceptable(request);
56+
},
57+
} as never,
58+
() => "test-context",
59+
);
60+
61+
const request = new Request("https://example.com/");
62+
const response = expectResponse(await middleware(
63+
{ request } as never,
64+
() => Promise.resolve(new Response("Not found", { status: 404 })),
65+
));
66+
strictEqual(capturedRequest, request);
67+
strictEqual(capturedContextData, "test-context");
68+
strictEqual(response.status, 406);
69+
strictEqual(response.headers.get("Vary"), "Accept");
70+
});
71+
72+
test(
73+
"self-reference CommonJS require exposes working Astro middleware API",
74+
{ skip: "Deno" in globalThis },
75+
async () => {
76+
const mod = require("@fedify/astro") as typeof import("@fedify/astro");
77+
78+
strictEqual(typeof mod.fedifyIntegration, "function");
79+
strictEqual(typeof mod.fedifyMiddleware, "function");
80+
81+
let nextCalled = false;
82+
const middleware = mod.fedifyMiddleware(
83+
{
84+
fetch(
85+
_request: Request,
86+
options: { onNotFound(request: Request): Promise<Response> },
87+
) {
88+
return options.onNotFound(new Request("https://example.com/actor"));
89+
},
90+
} as never,
91+
() => undefined,
92+
);
93+
94+
const response = expectResponse(await middleware(
95+
{ request: new Request("https://example.com/inbox") } as never,
96+
() => {
97+
nextCalled = true;
98+
return Promise.resolve(new Response("Handled by Astro"));
99+
},
100+
));
101+
102+
strictEqual(nextCalled, true);
103+
strictEqual(response.status, 200);
104+
strictEqual(await response.text(), "Handled by Astro");
105+
},
106+
);

packages/astro/tsdown.config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,10 @@ export default defineConfig({
55
dts: true,
66
format: ["esm", "cjs"],
77
platform: "node",
8+
outExtensions({ format }) {
9+
return {
10+
js: format === "cjs" ? ".cjs" : ".js",
11+
dts: format === "cjs" ? ".d.cts" : ".d.ts",
12+
};
13+
},
814
});

0 commit comments

Comments
 (0)