I have a project that includes a node_modules directory in the root package directory. This directory, like most node_modules directories is quite large (122MB across 17k files and directories).
When I open this package in Xcode directly (running xed . from package root), this directory seems to be causing some undesirable behavior:
Xcode takes noticeably longer to open the project.
XCBBuildService runs at 100% CPU for about a minute when opening a package for the first time on my MacBook Pro, which makes me thing that this is Xcode indexing the contents of node_modules.
"Find in Package" (⇧⌘F) search must be scoped to Sources or Tests to produce meaningful results.
None of these are critical issues, but they are inconvenient. (And I suspect that more developers will start to face this starting in Swift 5.3 because of SE-0271 — especially for projects relating to the web)
Is there any way to exclude certain files or directories from the project Xcode generates for the package?
One workaround that I tried was to run swift package generate-xcodeproj and remove the folder reference from the project. However, there were a few problems with this approach:
The generated project has problems linking libxml2 for dependencies that use that library, whereas SPM is able to build the project just fine.
The project must be regenerated (and subsequently re-edited) whenever a dependency is added or removed.
The generated project isn't as convenient as the interface Xcode provides when opening a package directly.
There's no way to exclude parts of the package from being visible to Xcode today. I think we considered providing the option to only see contents which are referenced by any package targets at some point, but that would be more of a filter, not really changing most of the issues you're seeing (except maybe "Find in Package").
Since hidden directories are excluded, we can look into that as a stop-gap solution. That said I think having a way to exclude folders, either directly in Xcode preferences or as part of SPM configuration would be really useful for heterogenous source projects like this one.
Thanks for your response. Please do consider options for supporting use cases like this in the future — especially as SPM expands to support new product types, and Swift starts to be incorporated into multi-language projects.
I just realised that there is a way to do this, albeit it is more of a workaround. If you place a Package.swift in the directory you want to exclude, Xcode should ignore it.
Sorry for digging up this topic!
I'm having a similar problem, but the workaround you described seems to work no longer. Does the Package.swift need to have any meaningful content? I've basically just added an empty Package.swift to the directory I'd like to exclude.
This would be awesome. I had to use the Package.swift to a monorepo where I also have a website with a node_modules directory. Xcode was very slow because it tried to index the content inside node_modules.