Skip to content

Commit 9760fdc

Browse files
authored
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
1 parent 0b4a44a commit 9760fdc

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

.github/workflows/deno-ci.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
- v1.41
1717
- v1.43
1818
- v1.45
19+
- v2.0
1920
- canary
2021
fail-fast: false # run each branch to completion
2122

generation/codegen-structs.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ export function generateStructsTypescript(surface: SurfaceMap, apiS: SurfaceApi)
291291
chunks.push('{');
292292
for (const [field, inner] of shape.fields) {
293293
const isReq = shape.required.includes(field);
294-
chunks.push(` ${field}${isReq ? '' : '?'}: ${generateType(inner)}${isReq ? '' : ' | null'};`);
294+
chunks.push(` ${maybeQuote(field)}${isReq ? '' : '?'}: ${generateType(inner)}${isReq ? '' : ' | null'};`);
295295
}
296296
chunks.push('}');
297297
return chunks.join('\n').replace(/\n/g, '\n ');

generation/codegen.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ export async function writeApiModule(surface: SurfaceMap, api: SurfaceApi, categ
88

99
function postProcess(text: string) {
1010
if (apisModuleRoot) {
11-
text = text.replaceAll(/from "..\/..\//g, `from "${apisModuleRoot}`);
11+
text = text.replaceAll(/from "..\/..\/([^"]+)"/g, (_, path) => {
12+
if (apisModuleRoot.startsWith('jsr:') && path.includes('@')) {
13+
return `from "${apisModuleRoot}${path.split('/')[1].replace('@', '/')}"`;
14+
} else {
15+
return `from "${apisModuleRoot}${path}"`;
16+
}
17+
});
1218
}
1319
return text;
1420
}

lib/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ see `/x/kubernetes_client` for more information.
3232

3333
## Changelog
3434

35+
* `v0.5.3` on `2024-10-16`:
36+
* Fix CRD codegen issues with particular definitions and when using JSR import paths.
37+
3538
* `v0.5.2` on `2024-09-28`:
3639
* Includes 'builtin' APIs generated from K8s `v1.30.4`.
3740
* New kinds `ValidatingAdmissionPolicy`, `ServiceCIDR`, `ResourceSlice`

0 commit comments

Comments
 (0)