Cli: Add `clean` command

Created on 14 May 2019  ยท  10Comments  ยท  Source: react-native-community/cli

Describe the Feature

I catch myself quite often recommending react-native-surrender to technical but mostly non-technical people to get to a _clean state_ when working with react-native. It would be nice to have an official clean command that cleans up dependencies such as from yarn or cocoapods as well as Xcode, Android and watchman cache.

In this idea it would automatically get what is used without the need to specify it (e.g. check for yarn.lock file, ios/Podfile, etc).

Possible Implementations

react-native clean
react-native clean --ios # only to clean iOS-related stuff
react-native clean --android # only for Android

# Maybe these โ“
react-native clean --no-pods # clean everything except pods
react-native clean --no-yarn
discussion

Most helpful comment

I am okay with almost any slicing (by layer - ios/android/react-native modules, by system - metro/node_modules/watchman/etc) so long as there is at least one simple version (perhaps the default? or something that sounds thorough like 'deep-clean") that eradicates absolutely every single bit of state it is possible to eradicate, ideally leaving you with what you would have if you just finished installing base system / dev installers and had done a git clone on a repo

All 10 comments

I am okay with almost any slicing (by layer - ios/android/react-native modules, by system - metro/node_modules/watchman/etc) so long as there is at least one simple version (perhaps the default? or something that sounds thorough like 'deep-clean") that eradicates absolutely every single bit of state it is possible to eradicate, ideally leaving you with what you would have if you just finished installing base system / dev installers and had done a git clone on a repo

So I thought a plugin might be just as good, maybe? and I saw this existing project that was close to working as a plugin, so I did a thing: https://github.com/pmadruga/react-native-clean-project/pull/12

@mikehardy: IMO a plugin should be fine as long as we can recommend it _in official channels_.

Yeah - agreed about that ability to recommend or not. I'd leave it to the repo author, and if not, it will form the basis for a possible internal implementation, sort of an incubator of the idea

Just cross-posting status for anyone following along: I have some good feedback to respond to on the PR, but it appears the repo maintainer likes it, so leaving the discussion of "recommandable in official channels" aside, that repo will have a nice clean plugin within a couple days

Final cross-post on this, but worth mentioning that the react-native-clean-project with my PR to do react-native clean-project-auto was accepted, merged, and has been published as version 3.2.1 on npmjs.com.

I believe a 3rd party plugin is good enough to be recommended through official channels so this issue might be resolved by that PR.

I'm already recommending it to anyone for obvious state issues (haste map stuff, weird type errors after package upgrades etc) and it seems to work fine.

@cpojer @kelset: what do you think about recommending @mikehardy's solution on the documentation in a troubleshooting section?

Is there a desire to move functionality like this to react-native-cli?

I have some semi-finished work for a "clean" command. I hadn't seen @mikehardy 's plugin before, but that does look promising. I'll look into it more.

However, I really like the idea of a clean script that has official blessing from react-native.

Just a note to say that react-native-clean-project isn't my plugin, I just found @pmadruga's work when I was looking for a clean function, and simply PR things there any time I find some new nook or cranny that isn't cleaned yet. So far seems thorough to me

I was considering doing the same, PR-ing to an existing project. There are other similar projects, such as rn-game-over: https://github.com/taboulot/rn-game-over

If we think an official implementation of this should be part of react-native-cli then I'm happy to move forward and PR it.

Was this page helpful?
0 / 5 - 0 ratings