Commit a933e02
authored
fix: allow project creation in directories with only .git folder (#866)
<!-- Please provide enough information so that others can review your
pull request. -->
<!-- Keep pull requests small and focused on a single change. -->
### Summary
#### Problem
Currently, the library validation prevents creating projects in
directories that contain any files, including `.git` folders. This
creates a frustrating user experience when:
1. Users clone an empty GitHub repository
2. The directory contains only a `.git` folder
3. The validation fails with "Directory already exists" error
This is a common workflow where developers create a GitHub repo first,
then clone it locally to set up their React Native library.
<img width="838" alt="image"
src="https://github.com/user-attachments/assets/85813b62-6954-4775-9794-c065de446f79"
/>
#### Solution
- Treat directories as "empty" if they contain no files OR only a `.git`
folder
- Allow project creation in such directories
This follows the same pattern used by Vite's `create-vite` tool:
- [Vite source
code](https://github.com/vitejs/vite/blob/b135918b91e8381c50bd2d076d40e9a65fe68bfe/packages/create-vite/src/index.ts#L589)
### Test plan
1. yarn install
2. cd packages/create-react-native-library
3. yarn prepare
4. run `./bin/create-react-native-library`
Tested scenarios:
- [x] Empty directory - works as before
- [x] Directory with only `.git` - now works ✅
- [x] Directory with other files - still blocked as expected
- [x] Non-existent directory - works as before
<!-- List the steps with which we can test this change. Provide
screenshots if this changes anything visual. -->1 parent 05ece3e commit a933e02
1 file changed
+17
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
217 | 217 | | |
218 | 218 | | |
219 | 219 | | |
220 | | - | |
221 | | - | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
222 | 237 | | |
223 | 238 | | |
224 | 239 | | |
| |||
0 commit comments