Commit 3e6384e
committed
feat(spm): clean scoping flags + JS-root cwd guard
Two related changes to setup-apple-spm.
* `npx react-native spm clean` gains scoping flags. Default behavior is
unchanged (generated dirs only). Each flag widens the deletion scope:
--project also Package.swift + <App>-SPM.xcodeproj/
--derived-data also ~/Library/Developer/Xcode/DerivedData/<App>-SPM-*
--cache also the current resolved-nightly cache slot under
~/Library/Caches/com.facebook.ReactNative/spm-artifacts/
--all shorthand for the three above
--yes skip confirmation for destructive scopes; non-TTY auto-confirms
Refactored cleanGeneratedState() to a pure gatherCleanTargets(appRoot, opts)
enumerator plus a thin I/O wrapper. App name for the DerivedData glob is
discovered from any *-SPM.xcodeproj actually present in appRoot, so the
scope can't accidentally hit DerivedData entries that don't belong to
this app. Cache slot is resolved via the same resolveCacheSlotVersion
used elsewhere, so the nightly-hash-keyed slot is targeted (not a stale
'1000.0.0/' or 'nightly/' label).
* A guard refuses runs from the JS root of a standard RN app, where the
community CLI writes autolinking.json under <projectRoot>/ios/... but
every SPM script anchors on cwd. The result was a silently-broken build:
the autolinker missed autolinking.json, generated an empty Autolinked
package, the build compiled fine, and any native module crashed at
runtime. describeRnRootMismatch returns a "cd ios && ..." message when
cwd === projectRoot AND <projectRoot>/ios/ exists as a directory.
Flat layouts (rn-tester) are explicitly safe — no ios/ subdir, no
refusal — and covered by a regression test.
* 13 new unit tests in setup-apple-spm-test.js: 9 for gatherCleanTargets
(each flag in isolation, additive composition, missing-xcodeproj edge
case) and 4 for describeRnRootMismatch (RN layout triggers, subdir
doesn't, flat layout doesn't, non-directory `ios` entry doesn't).
149/149 SPM tests pass.1 parent e4deda8 commit 3e6384e
4 files changed
Lines changed: 537 additions & 17 deletions
File tree
- packages/react-native
- scripts
- spm
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
165 | 165 | | |
166 | 166 | | |
167 | 167 | | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
168 | 193 | | |
169 | 194 | | |
170 | 195 | | |
| |||
198 | 223 | | |
199 | 224 | | |
200 | 225 | | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
201 | 231 | | |
202 | 232 | | |
203 | 233 | | |
| |||
0 commit comments