Skip to content

feat: generate TypeScript types after sync and init#48

Merged
angeloashmore merged 1 commit intomainfrom
aa/codegen-after-sync
Mar 12, 2026
Merged

feat: generate TypeScript types after sync and init#48
angeloashmore merged 1 commit intomainfrom
aa/codegen-after-sync

Conversation

@angeloashmore
Copy link
Member

@angeloashmore angeloashmore commented Mar 12, 2026

Resolves:

Description

Automatically generates prismicio-types.d.ts using prismic-ts-codegen after syncing models from Prismic. This runs after both sync (including watch mode) and init, so type definitions stay in sync with remote content models without a separate manual step.

Checklist

  • A comprehensive Linear ticket, providing sufficient context and details to facilitate the review of the PR, is linked to the PR.
  • If my changes require tests, I added them.
  • If my changes affect backward compatibility, it has been discussed.
  • If my changes require an update to the CONTRIBUTING.md guide, I updated it.

Preview

How to QA 1


Note

Medium Risk
Automatically writing prismicio-types.d.ts after model sync adds a new side effect that can overwrite local type definitions and may impact projects with custom type generation workflows.

Overview
After prismic init and prismic sync, the CLI now auto-generates prismicio-types.d.ts from the freshly synced remote Custom Type and Slice models using prismic-ts-codegen.

In sync --watch, type generation is also re-run whenever remote model changes are detected, via a new shared generateAndWriteTypes helper.

Written by Cursor Bugbot for commit 8982265. This will update automatically on new commits. Configure here.

Footnotes

  1. Please use these labels when submitting a review:
    ❓ #ask: Ask a question.
    💡 #idea: Suggest an idea.
    ⚠️ #issue: Strongly suggest a change.
    🎉 #nice: Share a compliment.

Run prismic-ts-codegen after syncing models to automatically generate
prismicio-types.d.ts, keeping type definitions in sync with remote
content models.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@angeloashmore angeloashmore marked this pull request as ready for review March 12, 2026 02:41
@angeloashmore angeloashmore merged commit 006e9b2 into main Mar 12, 2026
21 of 22 checks passed
@angeloashmore angeloashmore deleted the aa/codegen-after-sync branch March 12, 2026 02:43
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

customTypes: customTypes.map((customType) => customType.model),
slices: slices.map((slice) => slice.model),
projectRoot,
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated type regeneration logic across two files

Low Severity

The inline code in init.ts that calls framework.getSlices(), framework.getCustomTypes(), framework.getProjectRoot(), and then generateAndWriteTypes() is an exact duplicate of the regenerateTypes function in sync.ts. If the codegen behavior ever needs to change (e.g., different options, added error handling), both locations need updating, and forgetting one would introduce a bug. The regenerateTypes helper could live in codegen.ts and be shared.

Additional Locations (1)
Fix in Cursor Fix in Web

changed.push("custom types");
}

await regenerateTypes(framework);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hash updates before codegen prevents retry on failure

Medium Severity

In the watch loop, lastRemoteSlicesHash and lastRemoteCustomTypesHash are updated (lines 140, 145) before regenerateTypes runs (line 149). If regenerateTypes throws, the error is caught by the outer catch, but the hashes are already committed. On the next poll, remote hashes match the stored hashes, so no changes are detected — the codegen is never retried for those changes. The prismicio-types.d.ts file remains stale until an entirely new remote change occurs.

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant