diff --git a/Sources/FigmaAPI/Model/Variables.swift b/Sources/FigmaAPI/Model/Variables.swift index 5f00859..27ef272 100644 --- a/Sources/FigmaAPI/Model/Variables.swift +++ b/Sources/FigmaAPI/Model/Variables.swift @@ -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] } diff --git a/Sources/FigmaExport/Loaders/Colors/ColorsVariablesLoader.swift b/Sources/FigmaExport/Loaders/Colors/ColorsVariablesLoader.swift index 2b2e4c6..5b8747b 100644 --- a/Sources/FigmaExport/Loaders/Colors/ColorsVariablesLoader.swift +++ b/Sources/FigmaExport/Loaders/Colors/ColorsVariablesLoader.swift @@ -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 diff --git a/Tests/FigmaAPITests/VariablesTests.swift b/Tests/FigmaAPITests/VariablesTests.swift new file mode 100644 index 0000000..c73e2fe --- /dev/null +++ b/Tests/FigmaAPITests/VariablesTests.swift @@ -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) + } +}