code-connect icon indicating copy to clipboard operation
code-connect copied to clipboard

CLI setup script fails with SwiftUI project

Open IlyaPuchkaTW opened this issue 11 months ago • 1 comments

When running through setup steps to configure figma connect with Xcode iOS application project the CLI fails to build code-connect package as it uses incorrect path. Xcode does not store package dependencies in the build directory, instead it uses DerivedData.

Full output

ilya.puchka@XN7N00NTLJ DemoAppExample % npx figma connect --token=xxx -v                 

   ┌─────────────────────────────────────────────────────────────────────────────────────┐
   │                                                                                     │
   │                               Welcome to Code Connect                               │
   │                                                                                     │
   │   Follow a few simple steps to connect your Figma design system to your codebase.   │
   │   When you're done, you'll be able to see your component code while inspecting in   │
   │                                  Figma's Dev Mode.                                  │
   │                                                                                     │
   │            Learn more at https://www.figma.com/developers/code-connect.             │
   │                                                                                     │
   │   Please raise bugs or feedback at https://github.com/figma/code-connect/issues.    │
   │                                                                                     │
   │   Note: This process will create and modify Code Connect files. Make sure you've    │
   │                 committed necessary changes in your codebase first.                 │
   │                                                                                     │
   └─────────────────────────────────────────────────────────────────────────────────────┘

Using "swift" parser as a file matching *.xcodeproj or Package.swift was found in /Users/ilya.puchka/ws/DemoAppExample. If this is incorrect, please check you are running Code Connect from your project root, or add a `parser` key to your config file. See https://github.com/figma/code-connect for more information.
Config file found, parsing /Users/ilya.puchka/ws/DemoAppExample using specified include globs

Using Figma file URL from config: https://www.figma.com/design/xxx

  Fetching component information from https://api.figma.com/v1/code_connect/xxx/cli_data

147 Figma components found in the Figma file across 62 pages.

✔ Select the pages with the Figma components you'd like to map (Press space to select and enter to continue) › Bottom sheet           - 1 Component (Bottom sheet)

Found Code Connect Swift package at /Users/ilya.puchka/ws/DemoAppExample/build/../../SourcePackages/checkouts/code-connect, building parser binary. This may take a few minutes if this is the first time you've run Code Connect.
Error returned from parser: Parser exited with code 1. Try re-running the command with --verbose for more information.

Please provide:

  • Code Connect CLI version: 1.3.1
  • Operating system: MacOS 14.7.1

IlyaPuchkaTW avatar Mar 05 '25 15:03 IlyaPuchkaTW

It works when instead of app target you create a library target with SPM (haven't tried setting it up with Xcode project). Then you have to build it using swift build from command line, this also requires adding supported platforms to package declaration. Then connecting and publishing works.

// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "DemoAppFigmaConnect",
    platforms: [
        .iOS(.v15),
        .macOS(.v13),
    ],
    products: [
        // Products define the executables and libraries a package produces, making them visible to other packages.
        .library(
            name: "DemoAppFigmaConnect",
            targets: ["DemoAppFigmaConnect"]),
    ],
    dependencies: [
        .package(url: "https://github.com/figma/code-connect", from: "1.0.0"),
    ],
    targets: [
        // Targets are the basic building blocks of a package, defining a module or a test suite.
        // Targets can depend on other targets in this package and products from dependencies.
        .target(
            name: "DemoAppFigmaConnect",
            dependencies: [
                .product(name: "Figma", package: "code-connect")
            ]
        ),
    ]
)

IlyaPuchkaTW avatar Mar 05 '25 16:03 IlyaPuchkaTW