Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions lib/codama-generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@ import fs from "fs";
import path from "path";
import { randomUUID } from "crypto";
import { createRequire } from "module";

// codama-renderers-dart@0.4.x mispublishes its exports map: the `import` condition
// points at a .mjs absent from the tarball. Load the working CJS build via require.
// Anchor on cwd rather than import.meta.url so this also compiles under the CJS test build.
const renderDart: typeof import("codama-renderers-dart").renderVisitor =
createRequire(path.join(process.cwd(), "package.json"))(
"codama-renderers-dart"
).renderVisitor;
import type { Language } from "./codama-types";
import { assertLanguageSupportedForIdl } from "./codama-compat";
import { getCodamaRootNode, getIdlProgramName } from "./idl-utils";
Expand Down Expand Up @@ -99,6 +91,13 @@ export async function generateFromIdl(
case "dart": {
const dartDir = path.join(tmpDir, `${programName}-dart-client`);
fs.mkdirSync(dartDir, { recursive: true });
// codama-renderers-dart@0.4.x mispublishes its ESM entry (exports `import` -> a
// .mjs absent from the tarball); load the working CJS build lazily here so a
// resolution failure can't break the other renderers at module load time.
const renderDart = createRequire(
path.join(process.cwd(), "package.json")
)("codama-renderers-dart")
.renderVisitor as typeof import("codama-renderers-dart").renderVisitor;
codama.accept(
renderDart(dartDir, {
formatCode: false,
Expand Down
6 changes: 6 additions & 0 deletions next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ const nextConfig: NextConfig = {
"memfs",
],

// codama-renderers-dart's broken exports map defeats Next's dependency tracer, so its
// files are missing from the serverless bundle. Force-include them for the generate route.
outputFileTracingIncludes: {
"/api/generate": ["./node_modules/codama-renderers-dart/**/*"],
},

async headers() {
return [
{
Expand Down
Loading