Skip to content

fix(code-connect): type-check figma templates so bob build passes - #155

Merged
HasanGocmen merged 1 commit into
mainfrom
fix/code-connect-verify
Nov 27, 2026
Merged

HasanGocmen merged 1 commit into
mainfrom
fix/code-connect-verify

Conversation

@ergenekonyigit-ty

Copy link
Copy Markdown
Collaborator

Problem

main (after #154) kırık: verify job'ı daha "Install dependencies" adımında patlıyor — run 45841920148. Sonraki tüm adımlar skipped.

npm error command sh -c npm run storybook-generate && bob build && husky install
code-connect/Button.figma.ts:4:19 - error TS2307: Cannot find module 'figma' ...
Found 34 errors in 30 files.
Error: Failed to build definition files.

npm ci → prepare → bob build projedeki tüm dosyaları tip kontrol ediyor. Code Connect template'leri import figma from 'figma' yapıyor ama figma sanal modülünün tipleri tsconfig.json'a hiç eklenmemişti.

Fix

  • tsconfig.json: @figma/code-connect/figma-types-no-require register edildi. Taban config types: ["react-native", "jest"] verdiği için liste override edilirken ikisi de korundu. -no-require varyantı seçildi: projede @types/node var, figma-types'ın global require tanımı NodeRequire'ı eziyor.
  • code-connect/template-helpers.ts (yeni): tipler eklenince ortaya çıkan 28 gerçek hata için. Figma v2 template API'si katman bulunamadığında throw etmek yerine ErrorHandle döndürüyor, dolayısıyla instance.findText('X').textContent artık tip geçmiyor ve eksik katmanda tüm snippet'i kırardı. findText / getEnum helper'ları narrowing yapıp boş değere düşüyor; 15 dosyadaki 28 çağrı bunlara taşındı.
  • docs/code-connect-guide.md: tsconfig örneği gerçek konfigle hizalandı + helper kuralı not edildi.

Davranış değişikliği yok: üretilen Codé Connect çıktısı aynı, sadece eksik katman durumunda patlamak yerine degrade ediyor.

Verification (local)

Adım Sonuç
npm ci (prepare: storybook-generate + bob build + husky) ✅ exit 0
npm run lint (eslint + tsc --noEmit + prettier) ✅
npm run icons:check ✅ (icon churn yok)
npm run test ✅ 60 suite / 1002 test / 130 snapshot
figma connect parse --exit-on-unreadable-files ✅ 30/30 template; helper esbuild ile inline bundle ediliyor, publish etkilenmiyor
package-lock.json değişmedi

`npm ci` runs `prepare` -> `bob build`, which type-checks the whole project.
The Code Connect templates import the virtual `figma` module but its types
were never registered, so main failed with TS2307 in 30 files (verify job,
run 45841920148).

- register `@figma/code-connect/figma-types-no-require` in tsconfig.json
  (no-require variant: the project ships @types/node, whose NodeRequire would
  otherwise be shadowed by the figma global `require` declaration)
- add code-connect/template-helpers.ts and route layer lookups through it:
  the v2 template API returns `ErrorHandle` instead of throwing, so
  `instance.findText('X').textContent` no longer type-checks and would break
  the whole snippet on a missing layer
- align the tsconfig snippet in docs/code-connect-guide.md with the real config
@HasanGocmen
HasanGocmen merged commit 268f1d7 into main Nov 27, 2026
12 checks passed
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 2.67.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants