Skip to content

Commit cbd8323

Browse files
committed
Optimize export
1 parent 7f6f618 commit cbd8323

File tree

7 files changed

+457
-62
lines changed

7 files changed

+457
-62
lines changed

bun.lock

Lines changed: 31 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
"license": "",
1717
"devDependencies": {
1818
"@figma/plugin-typings": "^1.123",
19-
"@rspack/cli": "^1.7.7",
20-
"@rspack/core": "^1.7.7",
19+
"@rspack/cli": "^1.7.8",
20+
"@rspack/core": "^1.7.8",
2121

2222
"husky": "^9.1",
2323
"typescript": "^5.9",

src/code-impl.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
extractCustomComponentImports,
2424
extractImports,
2525
} from './commands/exportPagesAndComponents'
26+
2627
export { extractCustomComponentImports, extractImports }
2728

2829
import { getComponentName, resetTextStyleCache } from './utils'

src/codegen/Codegen.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,25 @@ export function resetGlobalBuildTreeCache(): void {
5555
globalBuildTreeCache.clear()
5656
}
5757

58+
// Global asset node registry populated during buildTree().
59+
// Tracks nodes classified as SVG/PNG assets so callers (e.g. export commands)
60+
// can collect them without re-walking the Figma node tree via IPC.
61+
const globalAssetNodes = new Map<
62+
string,
63+
{ node: SceneNode; type: 'svg' | 'png' }
64+
>()
65+
66+
export function resetGlobalAssetNodes(): void {
67+
globalAssetNodes.clear()
68+
}
69+
70+
export function getGlobalAssetNodes(): ReadonlyMap<
71+
string,
72+
{ node: SceneNode; type: 'svg' | 'png' }
73+
> {
74+
return globalAssetNodes
75+
}
76+
5877
/**
5978
* Get componentPropertyReferences from a node (if available).
6079
*/
@@ -373,6 +392,11 @@ export class Codegen {
373392
// Handle asset nodes (images/SVGs)
374393
const assetNode = checkAssetNode(node)
375394
if (assetNode) {
395+
// Register in global asset registry for export commands
396+
const assetKey = `${assetNode}/${node.name}`
397+
if (!globalAssetNodes.has(assetKey)) {
398+
globalAssetNodes.set(assetKey, { node, type: assetNode })
399+
}
376400
const props = await getProps(node)
377401
props.src = `/${assetNode === 'svg' ? 'icons' : 'images'}/${node.name}.${assetNode}`
378402
if (assetNode === 'svg') {

src/codegen/__tests__/codegen-viewport.test.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { afterAll, beforeEach, describe, expect, test } from 'bun:test'
22
import { resetTextStyleCache } from '../../utils'
3-
import { Codegen, resetGlobalBuildTreeCache } from '../Codegen'
3+
import {
4+
Codegen,
5+
getGlobalAssetNodes,
6+
resetGlobalAssetNodes,
7+
resetGlobalBuildTreeCache,
8+
} from '../Codegen'
49
import { resetGetPropsCache } from '../props'
510
import { resetSelectorPropsCache } from '../props/selector'
611
import { ResponsiveCodegen } from '../responsive/ResponsiveCodegen'
@@ -47,19 +52,36 @@ import { ResponsiveCodegen } from '../responsive/ResponsiveCodegen'
4752

4853
beforeEach(() => {
4954
resetGlobalBuildTreeCache()
55+
resetGlobalAssetNodes()
5056
resetGetPropsCache()
5157
resetSelectorPropsCache()
5258
resetTextStyleCache()
5359
})
5460

5561
afterAll(() => {
5662
resetGlobalBuildTreeCache()
63+
resetGlobalAssetNodes()
5764
resetGetPropsCache()
5865
resetSelectorPropsCache()
5966
resetTextStyleCache()
6067
;(globalThis as { figma?: unknown }).figma = undefined
6168
})
6269

70+
describe('globalAssetNodes', () => {
71+
test('resetGlobalAssetNodes clears and getGlobalAssetNodes returns empty map', () => {
72+
resetGlobalAssetNodes()
73+
const assets = getGlobalAssetNodes()
74+
expect(assets.size).toBe(0)
75+
})
76+
77+
test('getGlobalAssetNodes returns readonly map', () => {
78+
const assets = getGlobalAssetNodes()
79+
expect(typeof assets.get).toBe('function')
80+
expect(typeof assets.has).toBe('function')
81+
expect(typeof assets.size).toBe('number')
82+
})
83+
})
84+
6385
function createComponentNode(
6486
name: string,
6587
variantProperties: Record<string, string>,

0 commit comments

Comments
 (0)