@akanjs/devkit 2.3.2-rc.6 → 2.3.2-rc.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -120,6 +120,32 @@ describe("PagesBundleBuilder", () => {
120
120
  expect(result.logs).toEqual([]);
121
121
  expect(result.outputs.some((output) => output.kind === "entry-point")).toBe(true);
122
122
  });
123
+
124
+ test("uses live server fetch instead of signal macro in server pages bundles", () => {
125
+ const source = [
126
+ 'import { makePageProto, registerClientRuntime } from "akanjs/client";',
127
+ 'import { FetchClient } from "akanjs/fetch";',
128
+ 'import * as cnst from "./cnst";',
129
+ 'import { getSerializedSignal } from "./sig" with { type: "macro" };',
130
+ 'import type * as dict from "./dict";',
131
+ 'import type * as signal from "./sig";',
132
+ "",
133
+ "const dictionary = {};",
134
+ "const pageProto = makePageProto<typeof dict>(dictionary);",
135
+ "const fetchProto = FetchClient.build<typeof signal>(cnst, getSerializedSignal(), { Err: pageProto.Err });",
136
+ 'export const runtime = registerClientRuntime({ ...pageProto, ...fetchProto }, { scope: "app" });',
137
+ "",
138
+ ].join("\n");
139
+
140
+ const transformed = PagesBundleBuilder.transformServerUseClientFetchSource(source);
141
+
142
+ expect(transformed).toContain('import { fetch as serverFetch } from "./sig";');
143
+ expect(transformed).toContain(
144
+ "const fetchProto = FetchClient.build<typeof signal>(cnst, serverFetch.serializedSignal, { Err: pageProto.Err, base: serverFetch });",
145
+ );
146
+ expect(transformed).not.toContain("getSerializedSignal");
147
+ expect(transformed).not.toContain('with { type: "macro" }');
148
+ });
123
149
  });
124
150
 
125
151
  describe("CsrArtifactBuilder", () => {
@@ -65,6 +65,7 @@ export class PagesBundleBuilder {
65
65
  plugins: [
66
66
  PagesBundleBuilder.createPagesEntryPlugin(entrySource),
67
67
  PagesBundleBuilder.createServerCssStubPlugin(),
68
+ PagesBundleBuilder.createServerUseClientFetchPlugin(),
68
69
  await createExternalizeFrameworkPlugin({ app: this.#app, extra: akanConfig.externalLibs }),
69
70
  akanConfig.barrelImports.length > 0
70
71
  ? await createBarrelImportsPlugin(this.#app, {
@@ -147,4 +148,38 @@ export class PagesBundleBuilder {
147
148
  },
148
149
  };
149
150
  }
151
+
152
+ static createServerUseClientFetchPlugin(): BunPlugin {
153
+ return {
154
+ name: "akan-server-use-client-fetch",
155
+ setup(build) {
156
+ build.onLoad({ filter: /[/\\]lib[/\\]useClient\.(ts|tsx|js|jsx)$/ }, async (args) => {
157
+ const source = await Bun.file(args.path).text();
158
+ const transformed = PagesBundleBuilder.transformServerUseClientFetchSource(source);
159
+ if (transformed === source) return undefined;
160
+ return { contents: transformed, loader: loaderFor(args.path) };
161
+ });
162
+ },
163
+ };
164
+ }
165
+
166
+ static transformServerUseClientFetchSource(source: string): string {
167
+ if (!source.includes(`with { type: "macro" }`) || !source.includes("FetchClient.build")) return source;
168
+ return source
169
+ .replace(
170
+ /import\s+\{\s*getSerializedSignal\s*\}\s+from\s+["']\.\/sig["']\s+with\s+\{\s*type\s*:\s*["']macro["']\s*\};/,
171
+ `import { fetch as serverFetch } from "./sig";`,
172
+ )
173
+ .replace(
174
+ /const\s+fetchProto\s*=\s*FetchClient\.build<[^;]+;/,
175
+ "const fetchProto = FetchClient.build<typeof signal>(cnst, serverFetch.serializedSignal, { Err: pageProto.Err, base: serverFetch });",
176
+ );
177
+ }
178
+ }
179
+
180
+ function loaderFor(absPath: string): "ts" | "tsx" | "js" | "jsx" {
181
+ if (absPath.endsWith(".tsx")) return "tsx";
182
+ if (absPath.endsWith(".jsx")) return "jsx";
183
+ if (absPath.endsWith(".ts")) return "ts";
184
+ return "js";
150
185
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akanjs/devkit",
3
- "version": "2.3.2-rc.6",
3
+ "version": "2.3.2-rc.8",
4
4
  "sourceType": "module",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -32,7 +32,7 @@
32
32
  "@langchain/openai": "^1.4.6",
33
33
  "@tailwindcss/node": "^4.3.0",
34
34
  "@trapezedev/project": "^7.1.4",
35
- "akanjs": "2.3.2-rc.6",
35
+ "akanjs": "2.3.2-rc.8",
36
36
  "chalk": "^5.6.2",
37
37
  "commander": "^14.0.3",
38
38
  "daisyui": "^5.5.20",