Skip to content

Add Swift Package helper methods and fix test runner issue#45

Merged
EvanBacon merged 3 commits intomainfrom
fix/swift-package-helpers
Mar 2, 2026
Merged

Add Swift Package helper methods and fix test runner issue#45
EvanBacon merged 3 commits intomainfrom
fix/swift-package-helpers

Conversation

@EvanBacon
Copy link
Owner

Summary

New Helper Methods

PBXProject:

  • addPackageReference(ref) - Add a package reference to packageReferences
  • getPackageReference(identifier) - Find package by URL (remote) or path (local)
  • addRemoteSwiftPackage(opts) - Create and add remote package in one call
  • addLocalSwiftPackage(opts) - Create and add local package in one call

PBXNativeTarget:

  • addSwiftPackageProduct(opts) - Full wiring: creates product dependency, adds to target, creates build file, adds to frameworks phase
  • getSwiftPackageProductDependencies() - Returns all package product deps for target
  • removeSwiftPackageProduct(dep) - Removes product dep and cleans up build file

PBXBuildFile:

  • createFromProductRef(opts) - Creates build file for Swift package products (no fileRef required)

Usage Example

const project = XcodeProject.open(xcodeProjectPath);
const target = project.rootObject.getMainAppTarget("ios");

// Add package to project
const packageRef = project.rootObject.addLocalSwiftPackage({
  relativePath: "../node_modules/react-native",
});

// Add product to target (handles all wiring automatically)
const productDep = target.addSwiftPackageProduct({
  productName: "React",
  package: packageRef,
});

Bug Fixes

  • Made fileRef optional in PBXBuildFile JSON type (Swift package build files only have productRef)
  • Fixed Bun test runner error by using export type { AnyBuildPhase } instead of value export
  • Fixed circular dependency in utils/paths.ts by importing directly from source files

Test plan

  • All 634 existing tests pass
  • Added 50 new tests for Swift package functionality
  • Manual verification of end-to-end workflow

Closes #31

🤖 Generated with Claude Code

EvanBacon and others added 3 commits March 2, 2026 09:51
This PR addresses GitHub issue #31 by adding convenient helper methods
for working with Swift packages, and fixes a pre-existing Bun test
runner issue.

## New Helper Methods

**PBXProject:**
- `addPackageReference(ref)` - Add package reference to project
- `getPackageReference(identifier)` - Find package by URL or path
- `addRemoteSwiftPackage(opts)` - Create and add remote package
- `addLocalSwiftPackage(opts)` - Create and add local package

**PBXNativeTarget:**
- `addSwiftPackageProduct(opts)` - Full wiring: creates product dep,
  adds to target, creates build file, adds to frameworks phase
- `getSwiftPackageProductDependencies()` - Get all package deps
- `removeSwiftPackageProduct(dep)` - Remove with cleanup

**PBXBuildFile:**
- `createFromProductRef(opts)` - Create build file for Swift packages

## Bug Fixes

- Fixed `fileRef` to be optional in PBXBuildFile (required for SPM)
- Fixed Bun test runner "export not found" error by using proper
  `export type` for AnyBuildPhase in index.ts
- Fixed circular dependency in utils/paths.ts by importing directly
  from source files instead of index

## Tests

Added comprehensive tests for all new functionality (50 new tests).

Closes #31

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Cast json.objects access to any for property access.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@EvanBacon EvanBacon merged commit d9ea6c3 into main Mar 2, 2026
1 check passed
@EvanBacon EvanBacon deleted the fix/swift-package-helpers branch March 2, 2026 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SwiftPackage elements not working correctly

1 participant