fix(compiler): route the generated api object through the real buildApiRequest

Root-cause fix for the fix-round-1 review: the inlined query/body
assembly in __wrnexusCallApi was a third, unguarded copy of
buildApiRequest's rules. Restore the import of buildApiRequest from
@wrnexus/core in the generated module and delete the inline copy.

The four api-block-ssr.test.ts tests (and three in compiler.test.ts)
that dynamically import a generated module from an OS tmpdir were
failing against a stale globally-installed @wrnexus/core (v0.8.8,
predates buildApiRequest) because that tmpdir has no node_modules of
its own and bare-specifier resolution walked out of the workspace.
Fixed at the source: symlink the workspace @wrnexus/core into each
tmpdir root before the dynamic import, the same way every in-repo
package already resolves it.
This commit is contained in:
2026-08-20 07:11:53 +05:30
parent 847b7010d1
commit 9dec811069
5 changed files with 56 additions and 38 deletions
+20 -1
View File
@@ -1,5 +1,5 @@
import { test, expect } from "bun:test";
import { writeFileSync, mkdirSync, mkdtempSync, rmSync } from "node:fs";
import { writeFileSync, mkdirSync, mkdtempSync, rmSync, symlinkSync, existsSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { pathToFileURL } from "node:url";
@@ -7,6 +7,23 @@ import { generate, parse } from "../src/index.ts";
import { compileWrnFile } from "../src/index.ts";
import { mountHtml } from "@wrnexus/test";
// The compiled module below is written to an OS tmpdir with no node_modules
// of its own, so Node's bare-specifier resolution for "@wrnexus/core" would
// otherwise walk up to whatever (possibly stale, globally-installed) copy
// happens to sit outside the workspace. Symlink the workspace package in so
// it resolves to the real, currently-built `@wrnexus/core` — the same one
// every other package in this repo gets via its own
// `node_modules/@wrnexus/core` symlink.
const WORKSPACE_CORE = join(import.meta.dir, "../../core");
function linkWorkspaceCore(root: string): void {
const scopeDir = join(root, "node_modules", "@wrnexus");
const linkPath = join(scopeDir, "core");
if (existsSync(linkPath)) return;
mkdirSync(scopeDir, { recursive: true });
symlinkSync(WORKSPACE_CORE, linkPath, process.platform === "win32" ? "junction" : "dir");
}
test("explicit static rendering disables hydration metadata", () => {
const output = compileWrnFile(`page StaticPage {
render = "static"
@@ -33,6 +50,7 @@ let seq = 0;
async function compileAndImport(src: string): Promise<Record<string, unknown>> {
const dir = join(tmpdir(), "wrn-compiler-test");
mkdirSync(dir, { recursive: true });
linkWorkspaceCore(dir);
const file = join(dir, `m${seq++}.ts`);
writeFileSync(file, compileWrnFile(src));
return import(pathToFileURL(file).href);
@@ -1351,6 +1369,7 @@ test("page state SSR condition renders without ReferenceError", async () => {
const generatedFile = join(root, "pricing.generated.ts");
try {
linkWorkspaceCore(root);
const source = `
page Pricing {
state billingCycle = "monthly"