Proposal: Add Swift Package Manager Adapter for `tuist inspect implicit-imports’
Summary
Add support for pure Swift Package Manager (SPM) projects to the tuist inspect implicit-imports command by implementing an SPM adapter. This will allow Tuist to detect implicit dependencies in Swift Package projects without requiring Tuist manifest files.
Motivation
Currently, the tuist inspect implicit-imports command only works with Tuist-managed projects. However, many Swift developers use pure SPM projects without Tuist manifests.
Proposed Solution
Architecture Overview
The implementation follows the existing adapter pattern used in the reference implementation ([ImplicitChecker]( GitHub - rofle100lvl/ImplicitChecker )). The solution involves:
-
SPM Adapter A new adapter that uses
swift package describe --type jsonto extract package information -
Integration: Plug the adapter into the existing
inspect implicit-importsflow -
Minimal changes: Reuse existing implicit import detection logic
Implementation Details
- SPM Adapter Component
Create a new SPMProjectAdapter that:
-
Detects if the current directory contains a
Package.swiftfile -
Executes
swift package describe --type jsonto get package metadata -
Parses the JSON output to extract target information
-
Converts SPM target descriptions to Tuist’s internal graph representation
- SPM Package Description Models
Define models to parse swift package describe JSON output:
struct SPMPackageDescription: Codable {
let targets: [SPMTargetDescription]
}
struct SPMTargetDescription: Codable {
let name: String
let sources: [String]
let path: String
let targetDependencies: [String]
let productDependencies: [String]
}
- Integration Points
Location: Sources/TuistKit/Services/InspectImplicitImportsService.swift\
The service should:
-
Detect project type (Tuist manifest vs SPM). By default it would be tuist, but if there is no tuist project in the folder - than SPM
-
Use appropriate adapter to load project structure
-
Run existing implicit import detection logic
-
Report findings
#### 4. Reuse Existing Logic
The core implicit import detection logic can be reused:
-
Target scanning: Scan source files for import statements
-
Dependency analysis: Compare imported modules against declared dependencies
-
Reporting: Use existing error reporting mechanisms
Example Usage
# For SPM projects
cd MySwiftPackage
tuist inspect implicit-imports
# For Tuist projects (existing behavior)
cd MyTuistProject
tuist inspect implicit-imports
### Expected Output
```
Inspecting implicit imports…
✗ Found implicit dependencies:
- NetworkModule implicitly depends on: CoreModule
- UIModule implicitly depends on: CoreModule, NetworkModule
Run ‘swift package edit’ to add missing dependencies.
```
Or on success:
```
✓ No implicit dependencies found in your project.
```
## References
- Reference implementation: [ImplicitChecker]( GitHub - rofle100lvl/ImplicitChecker )
-–
**Author**: @rofle100lvl
**Date**: 2025-12-05