Skip to content

Commit

Permalink
Codegen fixups concerning dashes and jsr deps (#17)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
danopia authored Oct 16, 2024
1 parent 0b4a44a commit 9760fdc
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/deno-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
- v1.41
- v1.43
- v1.45
- v2.0
- canary
fail-fast: false # run each branch to completion

Expand Down
2 changes: 1 addition & 1 deletion generation/codegen-structs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ');
Expand Down
8 changes: 7 additions & 1 deletion generation/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 3 additions & 0 deletions lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down

0 comments on commit 9760fdc

Please sign in to comment.