feat(codegen): TypeScript-only generated bindings (Candid codegen V0)#183
feat(codegen): TypeScript-only generated bindings (Candid codegen V0)#183b3hr4d wants to merge 6 commits into
Conversation
…ctured Candid metadata evolution
…eactorBlock and renaming generated files to generated.ts.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b23375122e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // The TS compiler output ends with `declare const` signatures for the two | ||
| // runtime exports. Strip those — the JS implementation provides the values | ||
| // and we re-annotate them inline below. | ||
| const typeBlock = tsContent |
There was a problem hiding this comment.
Strip unused imports from generated .ts files
When a Candid service does not reference principals, didToTs still emits import type { Principal } ...; preserving that declaration block was harmless in .d.ts, but this commit now writes it into generated.ts. Projects with noUnusedLocals enabled, including this repo's base tsconfig, will fail type-checking on simple services like the updated snapshot with TS6196 for the unused Principal import, so the merge step needs to drop unused parser imports or render only imports required by the generated source.
Useful? React with 👍 / 👎.
| content.includes("createActorHooks(") | ||
| (content.includes("Auto-generated by @ic-reactor/codegen") && | ||
| content.includes("createActorHooks(")) || | ||
| content.includes('export * from "./index.generated"') |
There was a problem hiding this comment.
Preserve customized legacy wrappers
This broad substring check treats any existing index.ts that still re-exports ./index.generated as disposable and runCanisterPipeline overwrites the whole file with the new default wrapper. The old wrapper explicitly said it was safe to customize, so users who added query factories or app-specific hooks while keeping the re-export will lose that code on their first v4 regeneration; migrate only the exact managed wrapper or rewrite just the export line.
Useful? React with 👍 / 👎.
| * Skill install: npx skills add B3Pay/ic-reactor-skills --full-depth --skill ic-reactor-hooks | ||
| */ | ||
| export * from "./index.generated" | ||
| export * from "./generated" |
There was a problem hiding this comment.
Keep legacy reactor wrapper pointing at index.generated
generateReactorFile() is still exported and documented as the backward-compatible standalone index.generated.ts generator, but the companion generateReactorEntryFile() now returns an index.ts that re-exports ./generated. Any advanced caller that pairs these two public helpers as before will write index.generated.ts and then an entrypoint that imports a missing generated.ts, breaking the generated canister module.
Useful? React with 👍 / 👎.
Summary
First concrete step (V0) of the Candid compiler/codegen evolution:
@ic-reactor/codegennow emits TypeScript-only generated artifacts..didremains the source contract and is no longer copied into the frontend folder; parallel.js/.d.tsdeclaration files are dropped.New per-canister output
```text
/
generated.ts # typed service types + real idlFactory/init + (optional) reactor & hooks
index.ts # user-owned stable wrapper: export * from "./generated"
```
Config semantics are unchanged:
Changes
Constraints honored
Verification
Out of scope / follow-up
Checked-in example `index.generated.ts` artifacts, the CLI `--bindgen-only` help text, and codegen/CLI/vite READMEs are intentionally left untouched per the "do not edit generated example artifacts unless tests require it" constraint. They are now stale relative to the new output and should be regenerated/updated in a follow-up.
Relates to the evolution plan in `docs/plans/candid-compiler-codegen-evolution.md`.