Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Sources/FigmaAPI/Model/Variables.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public struct VariableCollectionValue: Decodable {
public var defaultModeId: String
public var id: String
public var name: String
public var remote: Bool?
public var modes: [Mode]
public var variableIds: [String]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class ColorsVariablesLoader {

let meta = try loadVariables(fileId: tokensFileId)

guard let tokenCollection = meta.variableCollections.first(where: { $0.value.name == tokensCollectionName })
guard let tokenCollection = meta.variableCollections.first(where: { $0.value.name == tokensCollectionName && $0.value.remote != true })
else { throw FigmaExportError.custom(errorString: "tokensCollectionName not found" ) }

let variables: [Variable] = tokenCollection.value.variableIds.compactMap { tokenId in
Expand Down
38 changes: 38 additions & 0 deletions Tests/FigmaAPITests/VariablesTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import XCTest
import Foundation
@testable import FigmaAPI

final class VariablesTests: XCTestCase {

func testLookupPrefersLocalOverRemoteWithSameName() throws {
let localId = "VariableCollectionId:1:4"
let remoteId = "VariableCollectionId:abc123def456/1:9"

let collections: [String: VariableCollectionValue] = [
localId: VariableCollectionValue(
defaultModeId: "1:0",
id: localId,
name: "Colors",
remote: false,
modes: [Mode(modeId: "1:0", name: "Light")],
variableIds: ["var1", "var2", "var3"]
),
remoteId: VariableCollectionValue(
defaultModeId: "1:0",
id: remoteId,
name: "Colors",
remote: true,
modes: [Mode(modeId: "1:0", name: "Light")],
variableIds: ["var1"]
)
]

let match = collections.first(where: {
$0.value.name == "Colors" && $0.value.remote != true
})

XCTAssertNotNil(match)
XCTAssertEqual(match?.key, localId)
XCTAssertEqual(match?.value.variableIds.count, 3)
}
}