From 9760fdc30f6c9717462856ca2aa922362b4f82a5 Mon Sep 17 00:00:00 2001 From: Daniel Lamando Date: Wed, 16 Oct 2024 21:55:50 +0200 Subject: [PATCH] Codegen fixups concerning dashes and jsr deps (#17) * fix(generation): Add a missing maybeQuote() Fixes #14 * feat(codegen): Support importing APIs from JSR Fixes #15 * Simplify conditional * Add a release note * ci: Add deno v2 --- .github/workflows/deno-ci.yaml | 1 + generation/codegen-structs.ts | 2 +- generation/codegen.ts | 8 +++++++- lib/README.md | 3 +++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deno-ci.yaml b/.github/workflows/deno-ci.yaml index 0b7ca22..039144c 100644 --- a/.github/workflows/deno-ci.yaml +++ b/.github/workflows/deno-ci.yaml @@ -16,6 +16,7 @@ jobs: - v1.41 - v1.43 - v1.45 + - v2.0 - canary fail-fast: false # run each branch to completion diff --git a/generation/codegen-structs.ts b/generation/codegen-structs.ts index de21c6c..74d5db7 100644 --- a/generation/codegen-structs.ts +++ b/generation/codegen-structs.ts @@ -291,7 +291,7 @@ export function generateStructsTypescript(surface: SurfaceMap, apiS: SurfaceApi) chunks.push('{'); for (const [field, inner] of shape.fields) { const isReq = shape.required.includes(field); - chunks.push(` ${field}${isReq ? '' : '?'}: ${generateType(inner)}${isReq ? '' : ' | null'};`); + chunks.push(` ${maybeQuote(field)}${isReq ? '' : '?'}: ${generateType(inner)}${isReq ? '' : ' | null'};`); } chunks.push('}'); return chunks.join('\n').replace(/\n/g, '\n '); diff --git a/generation/codegen.ts b/generation/codegen.ts index 8862797..bab28f6 100644 --- a/generation/codegen.ts +++ b/generation/codegen.ts @@ -8,7 +8,13 @@ export async function writeApiModule(surface: SurfaceMap, api: SurfaceApi, categ function postProcess(text: string) { if (apisModuleRoot) { - text = text.replaceAll(/from "..\/..\//g, `from "${apisModuleRoot}`); + text = text.replaceAll(/from "..\/..\/([^"]+)"/g, (_, path) => { + if (apisModuleRoot.startsWith('jsr:') && path.includes('@')) { + return `from "${apisModuleRoot}${path.split('/')[1].replace('@', '/')}"`; + } else { + return `from "${apisModuleRoot}${path}"`; + } + }); } return text; } diff --git a/lib/README.md b/lib/README.md index abcdff3..d0313ce 100644 --- a/lib/README.md +++ b/lib/README.md @@ -32,6 +32,9 @@ see `/x/kubernetes_client` for more information. ## Changelog +* `v0.5.3` on `2024-10-16`: + * Fix CRD codegen issues with particular definitions and when using JSR import paths. + * `v0.5.2` on `2024-09-28`: * Includes 'builtin' APIs generated from K8s `v1.30.4`. * New kinds `ValidatingAdmissionPolicy`, `ServiceCIDR`, `ResourceSlice`