Good catch. I can confirm the issue you’ve identified. The root cause is in flattenSingleDirectory — it counts all top-level entries (files and directories) via contentsOfDirectory, then bails out if the count isn’t exactly 1:
let entries = try await contentsOfDirectory(url.absolutePath)
guard entries.count == 1 else { return }
SPM’s stripFirstLevel, by contrast, filters to only consider directories at the top level before deciding whether to flatten. So in your case with:
- Package.swift (file)
- discarded/ (directory)
- Sources/
SPM sees one directory (discarded/) and flattens it, while SwifterPM sees two entries (Package.swift + discarded/) and skips flattening entirely — leaving the source paths broken.
Interestingly, SwifterPM already has a shouldStripFirstLevel function for binary artifacts that correctly counts only subdirectories [1], but this logic isn’t applied to registry source package extraction [2].
The fix would be to filter entries to only directories (and non-symlinks) before checking the count, matching SPM’s behavior.
To reply, just mention @dosu.
Share context across your team and agents. Try Dosu.