fix: add robust model removal from project#33
Merged
Conversation
Adds removeReference and removeFromProject methods to key project model classes, ensuring that targets and their exclusively-owned children (such as build phases, dependencies, configuration lists, and file references) are properly removed from the project. Updates PBXNativeTarget, PBXProject, PBXFileSystemSynchronizedRootGroup, PBXTargetDependency, and XCConfigurationList to support safe cascading deletion and reference cleanup. Extends tests to verify correct removal behavior and preservation of shared resources.
Moved isReferencing and removeReference implementations from subclasses to AbstractObject, providing a generic mechanism for reference management. This reduces code duplication and centralizes reference logic for easier maintenance.
Renamed the App Clip fixture file from 009-missing-app-clip-target.pbxproj to 009-expo-app-clip.pbxproj and updated all test references accordingly. Also reformatted some test code for improved readability.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request refactors reference tracking and cascade deletion across the Xcode project model. It centralizes and automates how objects track and remove references to each other, reducing repeated code and making cascade deletion (removing an object and its children only if they are not shared) more robust and easier to maintain. Documentation and tests are also updated to reflect these improvements.
Reference tracking and removal refactor:
isReferencingandremoveReferenceinAbstractObject, so most subclasses no longer need to implement these themselves. Now, reference tracking is driven by thegetObjectProps()pattern, which declares which properties are object references. (src/api/AbstractObject.ts,src/api/AbstractGroup.ts,src/api/AbstractTarget.ts,src/api/PBXNativeTarget.ts,src/api/PBXProject.ts,src/api/XCConfigurationList.ts, [1] [2] [3] [4] [5] [6] [7] [8]Cascade deletion improvements:
removeFromProject()methods for key classes (PBXNativeTarget,XCConfigurationList,PBXTargetDependency,PBXFileSystemSynchronizedRootGroup), ensuring that child objects are only deleted if they are exclusively owned by the parent, preventing accidental deletion of shared objects. (src/api/PBXNativeTarget.ts,src/api/XCConfigurationList.ts,src/api/PBXTargetDependency.ts,src/api/PBXFileSystemSynchronizedRootGroup.ts, [1] [2] [3] [4]Documentation updates:
CLAUDE.mdto document thegetObjectProps()pattern and best practices for implementing cascade deletion, making it easier for future contributors to follow and extend the system. Added details on fixture naming and round-trip testing for JSON fixtures. [1] [2]Testing improvements:
getReferrers. (src/api/__tests__/PBXNativeTarget.test.ts, [1] [2] [3]Type and import cleanups:
src/api/PBXNativeTarget.ts, src/api/PBXNativeTarget.tsL21)These changes make the codebase more maintainable, safer for large-scale refactoring, and easier for new contributors to understand and extend.