Skip to content

Commit ef2a9f0

Browse files
author
figma-bot
committed
Code Connect v1.3.2
1 parent cfed2bf commit ef2a9f0

File tree

12 files changed

+76
-24
lines changed

12 files changed

+76
-24
lines changed

CHANGELOG.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
1-
# Code Connect v1.3.1 (TBD)
1+
# Code Connect v1.3.3 (TBD)
2+
3+
# Code Connect v1.3.2
4+
5+
## Fixed
6+
7+
### General
8+
- Added support for GitHub Enterprise source links (fixes https://github.com/figma/code-connect/issues/259)
9+
10+
### React
11+
- Fixed incompatibility issue with React 19 (fixes https://github.com/figma/code-connect/issues/265)
12+
- Fixed issue with numeric characters in property names
13+
14+
### HTML
15+
- Allow examples to return strings to support icon IDs (fixes https://github.com/figma/code-connect/issues/252)
16+
17+
# Code Connect v1.3.1
218

319
## Fixed
420

cli/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@figma/code-connect",
3-
"version": "1.3.1",
3+
"version": "1.3.2",
44
"description": "A tool for connecting your design system components in code with your design system in Figma",
55
"keywords": [],
66
"author": "Figma",
@@ -61,10 +61,10 @@
6161
"benchmarking:run": "npx tsx ./src/connect/wizard/__test__/prop_mapping/prop_mapping_benchmarking.ts"
6262
},
6363
"devDependencies": {
64-
"@babel/core": "7.26.0",
65-
"@babel/generator": "7.26.2",
66-
"@babel/parser": "7.26.0",
67-
"@babel/types": "7.26.0",
64+
"@babel/core": "7.26.10",
65+
"@babel/generator": "7.26.10",
66+
"@babel/parser": "7.26.10",
67+
"@babel/types": "7.26.10",
6868

6969
"@storybook/csf-tools": "^8.4.7",
7070
"@types/cross-spawn": "^6.0.6",
@@ -108,7 +108,7 @@
108108
"ts-morph": "^23.0.0",
109109
"typescript": "5.5.4",
110110
"undici": "^5.28.4",
111-
"zod": "^3.23.8",
111+
"zod": "3.23.8",
112112
"zod-validation-error": "^3.2.0"
113113
}
114114
}

cli/src/connect/__test__/project.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,11 @@ describe('Project helper functions', () => {
110110
getRemoteFileUrl('/path/file.ts', 'https://[email protected]/myorg/myrepo/_git/myrepo'),
111111
).toBe('https://dev.azure.com/myorg/myrepo/_git/myrepo?path=/path/file.ts&branch=master')
112112
})
113+
114+
it('assumes GitHub-like structure for unknown urls', () => {
115+
expect(
116+
getRemoteFileUrl('/path/file.ts', 'https://my-custom-domain.com/myorg/myrepo.git'),
117+
).toBe('https://my-custom-domain.com/myorg/myrepo/blob/master/path/file.ts')
118+
})
113119
})
114120
})

cli/src/connect/api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export type EnumValue =
44
| number
55
| symbol
66
| undefined
7-
| JSX.Element
7+
| React.ReactElement
88
| Function
99
| Object
1010

@@ -38,7 +38,7 @@ export interface ConnectedComponent {
3838
* example: ({ icon }) => <Button icon={icon}/>,
3939
* }
4040
*/
41-
render<T = unknown>(renderFunction: (props: T) => JSX.Element): JSX.Element
41+
render<T = unknown>(renderFunction: (props: T) => React.ReactElement): React.ReactElement
4242
}
4343

4444
// This contains the base API interface for figma.connect calls across React and

cli/src/connect/parser_common.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,6 @@ export function getReferencedPropsForTemplate({
222222
}: {
223223
/** The prop mappings object */
224224
propMappings: PropMappings | undefined
225-
/** The set of referenced props */
226-
referencedProps?: Set<string>
227225
/** The top level node, used for error reporting */
228226
exp: ts.Node
229227
/** The source file */

cli/src/connect/project.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,8 @@ export function getRemoteFileUrl(filePath: string, repoURL?: string) {
523523
return `https://${url}?path=${relativeFilePath}&branch=${defaultBranch}`
524524
}
525525
} else {
526-
logger.error('Unsupported remote URL', url)
527-
return ''
526+
logger.debug('Unknown remote URL - assuming GitHub Enterprise', url)
527+
return `${url}/blob/${defaultBranch}${relativeFilePath}`
528528
}
529529
}
530530

cli/src/html/__test__/parser/examples/WrongSignatureNoHtmlTag.figma.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@ figma.connect('', {
55
visible: figma.boolean('Visible'),
66
label: figma.string('Label'),
77
},
8-
// @ts-expect-error
98
example: (props) => `<my-component visible=${props.visible}>${props.label}</my-component>`,
109
})

cli/src/html/parser.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import ts, { isTemplateExpression, SyntaxKind } from 'typescript'
1+
import ts, { isReturnStatement, isTemplateExpression, SyntaxKind } from 'typescript'
22
import {
33
stripQuotesFromNode,
44
parsePropertyOfType,
@@ -218,6 +218,39 @@ export function parseExampleTemplate(
218218
throw new ParserError(`Expected a body for the render function`, { sourceFile, node: exp })
219219
}
220220

221+
// If the body is a string literal, we generate a `figma.value` statement instead, which just
222+
// renders the string as-is in code examples
223+
if (ts.isStringLiteral(exp.body)) {
224+
const printer = ts.createPrinter()
225+
if (!exp.body) {
226+
throw new ParserError('Expected a function body', {
227+
sourceFile: parserContext.sourceFile,
228+
node: exp,
229+
})
230+
}
231+
let exampleCode = printer.printNode(ts.EmitHint.Unspecified, exp.body, sourceFile)
232+
233+
let templateCode = getParsedTemplateHelpersString() + '\n\n'
234+
235+
templateCode += `const figma = require('figma')\n\n`
236+
237+
templateCode += getReferencedPropsForTemplate({
238+
propMappings,
239+
exp,
240+
sourceFile,
241+
})
242+
243+
exampleCode = exampleCode.replace(/`/g, '\\`')
244+
245+
// Body is a string literal, so there aren't any placeholders
246+
templateCode += `export default figma.value(${exampleCode})\n`
247+
248+
return {
249+
code: templateCode,
250+
nestable: true,
251+
}
252+
}
253+
221254
const templateNode = getHtmlTaggedTemplateNode(exp.body)
222255

223256
if (!templateNode) {
@@ -389,7 +422,6 @@ export function parseExampleTemplate(
389422

390423
templateCode += getReferencedPropsForTemplate({
391424
propMappings,
392-
referencedProps,
393425
exp,
394426
sourceFile,
395427
})

cli/src/html/types.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { FigmaConnectMeta } from '../connect/api'
22
import { HtmlTemplateString } from './template_literal'
33

4-
export type HtmlMeta<P> = Required<Pick<FigmaConnectMeta<P, P, HtmlTemplateString>, 'example'>> &
5-
FigmaConnectMeta<P, P, HtmlTemplateString> & {
4+
export type HtmlMeta<P> = Required<
5+
Pick<FigmaConnectMeta<P, P, HtmlTemplateString | string>, 'example'>
6+
> &
7+
FigmaConnectMeta<P, P, HtmlTemplateString | string> & {
68
/**
79
* A list of import statements that will render in the Code Snippet in Figma.
810
*/

cli/src/react/index_react.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { getClient } from '../connect/index_common'
1818
import { ReactMeta } from './types'
1919

2020
const _client: FigmaConnectClient = getClient()
21-
const _figma: FigmaConnectAPI<ConnectedComponent, JSX.Element> & {
21+
const _figma: FigmaConnectAPI<ConnectedComponent, React.ReactElement> & {
2222
/**
2323
* Defines a code snippet that displays in Figma when a component is selected. This function has two signatures:
2424
* - When called with a component reference as the first argument, it will infer metadata such as the import statement

0 commit comments

Comments
 (0)