Skip to content

Commit 0b62c1f

Browse files
author
figma-bot
committed
Code Connect v1.4.2
1 parent 5e3d6c5 commit 0b62c1f

31 files changed

Lines changed: 1844 additions & 298 deletions

CHANGELOG.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
1+
# Code Connect v1.4.2 (16th March 2026)
2+
3+
## Fixed
4+
5+
### General
6+
7+
- Fixed incorrect `documentUrlSubstitutions` when one key is a prefix of another (e.g. `SearchInput` and `SearchInputMenu`). The CLI now processes longer keys first so the correct substitution is applied.
8+
- Publishing with `--batch-size` now retries automatically on rate-limit (429) and server error (5xx) responses, respecting the `Retry-After` header when present, rather than failing immediately
9+
- Fixed an issue around `.figma.js`/`.figma.ts` files being incorrectly treated as template files
10+
11+
### CLI
12+
13+
- The `--include-template-files` flag now shows a deprecation warning instead of causing an error. The flag is no longer necessary as template files are automatically included by default.
14+
15+
## Features
16+
17+
### General
18+
19+
- Code Connect now supports default branch names other than `master`/`main`. For cases where it can't be detected automatically, you can set `defaultBranch` in your `figma.config.json`.
20+
21+
### Template files
22+
23+
- Variant restrictions are now handled by the `migrate` script. These are inlined into one template file with if/else blocks.
24+
- TypeScript is now supported for raw template files (`.figma.template.ts` / `.figma.ts`).
25+
- ESM import syntax is now supported for the Figma API: `import figma from 'figma'`
26+
- Type-only imports (`import type`) are supported
27+
- Other module imports are not yet supported
28+
- To enable types for the `figma` API, add `"@figma/code-connect/figma-types"` to the `types` array in your `tsconfig.json`.
29+
- JavaScript files are the default output of the `migrate` command. Can pass `--typescript` to output TypeScript (`.figma.ts`) files instead.
30+
131
# Code Connect v1.4.1 (20th February 2026)
232

333
## Fixed

cli/figma-module.d.ts

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
/**
2+
* Type definitions for the `figma` module available in Code Connect template files
3+
* (.figma.ts).
4+
* Usage: add to your tsconfig.json:
5+
* { "compilerOptions": { "types": ["@figma/code-connect/figma-types"] } }
6+
*/
7+
// Declare require() for the 'figma' module so that template files can use
8+
// `const figma = require('figma')` without needing @types/node installed.
9+
declare function require(module: 'figma'): typeof import('figma')
10+
declare function require(module: string): any
11+
declare module 'figma' {
12+
export type CodeSection = { type: 'CODE'; code: string; nestedImports?: string[] }
13+
export type InstanceSection = {
14+
type: 'INSTANCE'
15+
guid: string
16+
symbolId: string
17+
resultSections?: ResultSection[]
18+
nestedImports?: string[]
19+
}
20+
export type SlotSection = { type: 'SLOT'; guid?: string; propertyName: string }
21+
export type ErrorSection = { type: 'ERROR'; message: string; errorObject?: unknown }
22+
export type ResultSection = CodeSection | InstanceSection | SlotSection | ErrorSection
23+
24+
export interface TemplateStringResult {
25+
sections: ResultSection[]
26+
language: string
27+
type: 'SECTIONS'
28+
}
29+
30+
export interface SelectorOptions {
31+
path?: string[]
32+
traverseInstances?: boolean
33+
}
34+
35+
type ObjectValue = Record<string, FCCValue>
36+
37+
export type FCCValue =
38+
| string
39+
| number
40+
| boolean
41+
| undefined
42+
| { $value: string; $type: 'jsx-element' }
43+
| { $value: string; $type: 'function' }
44+
| { $value: string; $type: 'identifier' }
45+
| { $value: ObjectValue; $type: 'object' }
46+
| { $value: string; $type: 'template-string' }
47+
| { $value: string; $type: 'react-component' }
48+
| { $value: FCCValue[]; $type: 'array' }
49+
50+
export interface TextHandle {
51+
readonly type: 'TEXT'
52+
readonly name: string
53+
__render__(): string
54+
}
55+
56+
export interface TemplateMetadata {
57+
nestable?: boolean
58+
props?: Record<string, unknown>
59+
__props: Record<string, unknown>
60+
[key: string]: unknown
61+
}
62+
63+
export interface ErrorHandle {
64+
readonly type: 'ERROR'
65+
__render__(): ResultSection[]
66+
executeTemplate(): {
67+
example: ResultSection[]
68+
metadata?: TemplateMetadata
69+
}
70+
}
71+
72+
export interface InstanceHandle {
73+
readonly type: 'INSTANCE'
74+
readonly symbolId: string
75+
readonly name: string
76+
readonly children: (InstanceHandle | TextHandle | ErrorHandle)[]
77+
readonly properties: Record<string, { value: string | boolean }>
78+
readonly path?: string[]
79+
readonly slots?: Record<string, { guid: string }>
80+
81+
codeConnectId(): string | null
82+
83+
__find__(name: string): InstanceHandle | ErrorHandle | null
84+
__findChildWithCriteria__(criteria: {
85+
type: 'INSTANCE' | 'TEXT'
86+
name: string
87+
}): InstanceHandle | TextHandle | ErrorHandle | null
88+
__getPropertyValue__(name: string): string | boolean | ErrorHandle
89+
__render__(): ResultSection[]
90+
__getProps__(): ResultSection[] | Record<string, unknown> | undefined
91+
__renderWithFn__(
92+
renderFn: (props: Record<string, unknown>) => TemplateStringResult,
93+
): ResultSection[] | ErrorHandle | undefined
94+
95+
getString(propName: string): string
96+
getBoolean(propName: string): boolean
97+
getBoolean<O extends Record<string, unknown>>(
98+
propName: string,
99+
options: O,
100+
): EnumOptionsValues<O>
101+
getEnum<O extends Record<string, unknown>>(
102+
propName: string,
103+
options: O,
104+
): EnumOptionsValues<O> | undefined
105+
getInstanceSwap(propName: string): InstanceHandle | undefined
106+
getSlot(propName: string): ResultSection[] | undefined
107+
hasCodeConnect(): boolean
108+
getPropertyValue(name: string): string | boolean | ErrorHandle
109+
findInstance(layerName: string, opts?: SelectorOptions): InstanceHandle | ErrorHandle
110+
findText(layerName: string, opts?: SelectorOptions): TextHandle | ErrorHandle
111+
findConnectedInstance(
112+
codeConnectId: string,
113+
opts?: SelectorOptions,
114+
): InstanceHandle | ErrorHandle | null
115+
findConnectedInstances(
116+
selectorFn: (node: InstanceHandle) => boolean,
117+
opts?: SelectorOptions,
118+
): (InstanceHandle | ErrorHandle)[]
119+
findLayers(
120+
selectorFn: (node: InstanceHandle) => boolean,
121+
opts?: SelectorOptions,
122+
): (InstanceHandle | TextHandle | ErrorHandle)[]
123+
executeTemplate(): {
124+
example: ResultSection[]
125+
metadata?: TemplateMetadata
126+
}
127+
}
128+
129+
export type LayerHandle = InstanceHandle | TextHandle | ErrorHandle
130+
131+
export type EnumOptionsValues<O extends Record<string, unknown>> = O[keyof O]
132+
133+
export interface FigmaProperties {
134+
string(propName: string): string
135+
boolean(propName: string): boolean
136+
boolean<O extends Record<string, unknown>>(propName: string, options: O): EnumOptionsValues<O>
137+
enum<O extends Record<string, unknown>>(
138+
propName: string,
139+
options: O,
140+
): EnumOptionsValues<O> | undefined
141+
// In error cases the implementation may return string (from TextHandle.__render__)
142+
instance(propName: string): ResultSection[] | string | undefined
143+
__instance__(
144+
propName: string,
145+
): InstanceHandle | TextHandle | ErrorHandle | ResultSection[] | undefined
146+
slot(propName: string): ResultSection[] | undefined
147+
children(layerNames: string[]): ResultSection[]
148+
}
149+
150+
export type TemplateLiteral = (
151+
strings: TemplateStringsArray,
152+
...values: unknown[]
153+
) => TemplateStringResult
154+
155+
export interface Figma {
156+
/** The currently selected component instance */
157+
readonly selectedInstance: InstanceHandle & { readonly __properties__: FigmaProperties }
158+
/** Alias for selectedInstance */
159+
readonly currentLayer: InstanceHandle & { readonly __properties__: FigmaProperties }
160+
/** Access component properties via the properties API */
161+
readonly properties: FigmaProperties
162+
163+
/** Template literal tag for custom/plaintext code */
164+
code: TemplateLiteral
165+
/** Template literal tag for JSX/TSX code */
166+
tsx: TemplateLiteral
167+
/** Template literal tag for HTML code */
168+
html: TemplateLiteral
169+
/** Template literal tag for Swift code */
170+
swift: TemplateLiteral
171+
/** Template literal tag for Kotlin/Compose code */
172+
kotlin: TemplateLiteral
173+
174+
/** Return a raw value (not rendered as a template string) */
175+
value(raw: unknown, preview?: unknown): { type: string; value: unknown; preview: unknown }
176+
177+
helpers: {
178+
react: {
179+
renderProp(name: string, prop: FCCValue | ResultSection[]): TemplateStringResult | string
180+
renderChildren(
181+
prop: FCCValue | ResultSection[],
182+
): ResultSection[] | string | number | boolean | TemplateStringResult
183+
renderPropValue(
184+
prop: FCCValue | ResultSection[],
185+
): string | number | boolean | ResultSection[]
186+
stringifyObject(obj: unknown): string
187+
jsxElement(value: string): { $value: string; $type: 'jsx-element' }
188+
function(value: string): { $value: string; $type: 'function' }
189+
identifier(value: string): { $value: string; $type: 'identifier' }
190+
object(value: ObjectValue): { $value: ObjectValue; $type: 'object' }
191+
templateString(value: string): { $value: string; $type: 'template-string' }
192+
reactComponent(value: string): { $value: string; $type: 'react-component' }
193+
array(value: FCCValue[]): { $value: FCCValue[]; $type: 'array' }
194+
isReactComponentArray(prop: unknown): boolean
195+
}
196+
swift: {
197+
renderChildren(children: ResultSection[], prefix: string): ResultSection[]
198+
}
199+
kotlin: {
200+
renderChildren(children: ResultSection[], prefix: string): ResultSection[]
201+
}
202+
}
203+
}
204+
205+
const figma: Figma
206+
export = figma
207+
}

cli/npm_catalog.toml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
"jest-cli" = "^29.7.0"
137137
"jest-junit" = "16.0.0"
138138
"ts-jest" = "^29.2.5"
139+
"just-bash" = "^2.10.2"
139140
"@types/lodash" = "4.17.20"
140141
"@types/lodash-es" = "4.17.12"
141142
"lodash" = "4.17.23"
@@ -173,8 +174,6 @@
173174
"tailwindcss" = "4.1.3"
174175
"@tanstack/react-router" = "1.130.0"
175176
"@tanstack/react-router-devtools" = "1.130.0"
176-
"@vitejs/plugin-react" = "4.4.1"
177-
"vite" = "6.3.6"
178177
"webpack" = "5.91.0"
179178
"webpack-cli" = "5.1.4"
180179
"modal" = "^0.6.0"
@@ -187,6 +186,7 @@
187186
"@modelcontextprotocol/sdk" = "1.24.0"
188187
"@opentelemetry/api" = "^1.9.0"
189188
"@sentry/cli" = "2.58.3"
189+
"@tanstack/react-virtual" = "3.13.18"
190190
"@types/jsdom" = "^21.1.7"
191191
"@types/mocha" = "10.0.10"
192192
"@types/node" = "22.17.2"
@@ -200,13 +200,14 @@
200200
"csstype" = "^3.2.3"
201201
"dayjs" = "^1.11.19"
202202
"esbuild" = "0.25.0"
203+
"flatted" = "^3.3.3"
203204
"jotai" = "2.9.3"
204205
"intl-messageformat" = "^10.7.14"
205206
"graphql" = "16.12.0"
206207
"jsdom" = "27.4.0"
207208
"knip" = "^5.27.3"
208-
"lightningcss" = "1.29.2"
209-
"mediabunny" = "1.25.8"
209+
"lightningcss" = "1.32.0"
210+
"mediabunny" = "1.34.4"
210211
"mocha" = "10.8.2"
211212
"mocha-junit-reporter" = "2.2.1"
212213
"postcss" = "8.5.2"
@@ -219,11 +220,13 @@
219220
"sinon" = "^17.0.1"
220221
"ts-morph" = "^27.0.0"
221222
"ts-node" = "^10.9.2"
223+
"tsx" = "4.21.0"
222224
"typescript" = "5.9.3"
223225
"yaml" = "2.8.0"
224226
"@zip.js/zip.js" = "2.8.19"
225227
"zod-to-json-schema" = "^3.23.5"
226228
"zod" = "3.25.58"
229+
"@anthropic-ai/claude-agent-sdk" = "0.2.69"
227230
"ai" = "4.1.62"
228231
"@ai-sdk/amazon-bedrock" = "2.1.4"
229232
"@ai-sdk/anthropic" = "1.2.5"

cli/package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@figma/code-connect",
3-
"version": "1.4.1",
3+
"version": "1.4.2",
44
"description": "A tool for connecting your design system components in code with your design system in Figma",
55
"keywords": [],
66
"author": "Figma",
@@ -18,6 +18,9 @@
1818
"./react": {
1919
"types": "./dist/react/index_react.d.ts",
2020
"default": "./dist/react/index_react.js"
21+
},
22+
"./figma-types": {
23+
"types": "./figma-module.d.ts"
2124
}
2225
},
2326
"repository": {
@@ -29,7 +32,8 @@
2932
"figma": "bin/figma"
3033
},
3134
"files": [
32-
"dist/**/*"
35+
"dist/**/*",
36+
"figma-module.d.ts"
3337
],
3438
"engines": {
3539
"node": ">=18"
@@ -83,7 +87,7 @@
8387
"pkg": "^5.8.1",
8488
"ts-jest": "^29.2.5",
8589
"ts-loader": "^9.5.1",
86-
"tsx": "^4.11.0",
90+
"tsx": "4.21.0",
8791
"webpack": "5.91.0",
8892
"webpack-cli": "5.1.4"
8993
},

0 commit comments

Comments
 (0)