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:
@@ -1,10 +1,29 @@
|
||||
import { afterEach, expect, test } from "bun:test";
|
||||
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { mkdirSync, mkdtempSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { parse } from "@wrnexus/syntax";
|
||||
import { generate } from "../src/codegen.ts";
|
||||
|
||||
// The generated module dynamically imported 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");
|
||||
mkdirSync(scopeDir, { recursive: true });
|
||||
symlinkSync(
|
||||
WORKSPACE_CORE,
|
||||
join(scopeDir, "core"),
|
||||
process.platform === "win32" ? "junction" : "dir",
|
||||
);
|
||||
}
|
||||
|
||||
const ROOT_TSCONFIG = join(import.meta.dir, "../../../tsconfig.json").replace(/\\/g, "/");
|
||||
// The repo's own tsc, not a `bunx`-fetched one — `bunx tsc` can resolve an
|
||||
// unrelated TypeScript version that doesn't understand this repo's tsconfig
|
||||
@@ -150,6 +169,7 @@ test("an ssr block used in {#each} with an error section runs the error body on
|
||||
const root = mkdtempSync(join(tmpdir(), "wrnexus-ssr-each-"));
|
||||
roots.push(root);
|
||||
mkdirSync(root, { recursive: true });
|
||||
linkWorkspaceCore(root);
|
||||
const file = join(root, "page.ts");
|
||||
writeFileSync(file, generated);
|
||||
|
||||
@@ -189,6 +209,7 @@ test("an ssr block's response body error is not swallowed by the error section",
|
||||
const root = mkdtempSync(join(tmpdir(), "wrnexus-ssr-response-throws-"));
|
||||
roots.push(root);
|
||||
mkdirSync(root, { recursive: true });
|
||||
linkWorkspaceCore(root);
|
||||
const file = join(root, "page.ts");
|
||||
writeFileSync(file, generated);
|
||||
|
||||
@@ -227,6 +248,7 @@ test("an ssr block still runs the error body on a genuine transport failure", as
|
||||
const root = mkdtempSync(join(tmpdir(), "wrnexus-ssr-transport-fails-"));
|
||||
roots.push(root);
|
||||
mkdirSync(root, { recursive: true });
|
||||
linkWorkspaceCore(root);
|
||||
const file = join(root, "page.ts");
|
||||
writeFileSync(file, generated);
|
||||
|
||||
@@ -263,6 +285,7 @@ test("an ssr block used in {#each} without an error section still propagates a f
|
||||
const root = mkdtempSync(join(tmpdir(), "wrnexus-ssr-each-propagate-"));
|
||||
roots.push(root);
|
||||
mkdirSync(root, { recursive: true });
|
||||
linkWorkspaceCore(root);
|
||||
const file = join(root, "page.ts");
|
||||
writeFileSync(file, generated);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user