Giter VIP home page Giter VIP logo

react-native-clean-project's Introduction

React Native Clean Project

npm version https://img.shields.io/github/license/pmadruga/react-native-clean-project.svg GitHub issues Build Status

Cleans your React Native project by purging caches and modules, and reinstalling them again.

Installing

yarn add -D react-native-clean-project

Running

React-Native CLI plugin

This module is automatically detected as a plugin by the standard react-native command, adding new sub-commands:

  • react-native clean-project-auto - fully automated project state clean: like a freshly-cloned, never-started repo
  • react-native clean-project - interactive project state clean: choose types of react-native state to clean

Direct execution

For complete control (including using command-line arguments to non-interactively fine-tune what state is cleaned):

npx react-native-clean-project

Or add it as a script to your package.json

"scripts": {
  "clean": "react-native-clean-project"
}

Content

This is a combination of the commands suggested in the React Native documentation plus others.

State Type Command In clean-project-auto? Optional? Default? Option Flag
React-native cache rm -rf $TMPDIR/react-* Yes No true
Metro bundler cache rm -rf $TMPDIR/metro-* Yes No true
Watchman cache watchman watch-del-all Yes No true
NPM modules rm -rf node_modules Yes Yes true --keep-node-modules
Yarn cache yarn cache clean Yes Yes true --keep-node-modules
Yarn packages yarn install No Yes true --keep-node-modules
NPM cache npm cache verify Yes Yes true --keep-node-modules
NPM Install npm ci Yes Yes true --keep-node-modules
iOS build folder rm -rf ios/build Yes Yes false --remove-iOS-build
iOS pods folder rm -rf ios/Pods Yes Yes false --remove-iOS-pods
system iOS pods cache pod cache clean --all Yes Yes true --keep-system-iOS-pods-cache
user iOS pods cache rm -rf ~/.cocoapods Yes Yes true --keep-user-iOS-pods-cache
Android build folder rm -rf android/build Yes Yes false --remove-android-build
Android clean project (cd android && ./gradlew clean) Yes Yes false --clean-android-project
Brew package brew update && brew upgrade No Yes true --keep-brew
Pod packages pod update No Yes true --keep-pods

Example: npx react-native-clean-project --remove-iOS-build

Other Tips

You can also reset the Metro bundler cache when starting with react-native start --reset-cache

Support

This library does not support windows. PR's are welcome.

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

react-native-clean-project's People

Contributors

alexanderwallin avatar andrewheekin avatar beaur avatar codybrouwers avatar dependabot[bot] avatar dijonkitchen avatar fdiskas avatar jack828 avatar mikehardy avatar mortentangen avatar pmadruga avatar r0b0t3d avatar shivamjoker avatar swrobel avatar whck6 avatar wilau2 avatar zachcoyle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-clean-project's Issues

Trying to use it on Jenkis pipeline

First of all, thanks for this amazing package.

The amount of hours our team is saving is incredible thanks to your work.

I am working on our pipeline (Jenkins) and I would like to use the package to do the cleanup.

My apologies if the issue is actually not related to your package, but I am not sure why this is happening.

The issue I am facing is that it seems when I do npm run clean("clean": "react-native clean-project-auto" on package.json),
the step on Jenkins doesn't result in success.

Do you have any idea why? It should log it as a success and move on to the next steps, but that is not the case.

It stays there for as much time as I let it be, without returning a success.

Thanks in advance!

Screen Shot 2021-08-30 at 5 39 45 PM

TypeError: answer.toLowercase is not a function

Version: >3.6.1

npx react-native-clean-project
npx: installed 1 in 1.551s
Wipe iOS build folder? (Y/n) y
readline.js:1154
            throw err;
            ^

TypeError: answer.toLowercase is not a function
    at checkAnswer (/Users/<User>/.npm/_npx/16899/lib/node_modules/react-native-clean-project/source/internals/options.js:57:19)
    at /Users/<User>/.npm/_npx/16899/lib/node_modules/react-native-clean-project/source/internals/options.js:77:22
    at /Users/<User>/.npm/_npx/16899/lib/node_modules/react-native-clean-project/source/internals/options.js:52:5
    at Interface._onLine (readline.js:335:5)
    at Interface._line (readline.js:666:8)
    at Interface._ttyWrite (readline.js:1010:14)
    at ReadStream.onkeypress (readline.js:213:10)
    at ReadStream.emit (events.js:315:20)
    at emitKeys (internal/readline/utils.js:345:14)
    at emitKeys.next (<anonymous>)

I downgraded to 3.6.1 and it works so this is clearly an issue with the latest release.

React Native for macOS Support

Microsoft has created a set of tools to support React Native on macOS. It would be nice to include support for it in this package.

I can supply the PR for it, but I'd like to know what the preference is for the contribution: 1. as one commit of all the changes encompassing the complete support; or 2. a series of commits where each shows a set of related changes (eg, askiOS/--removeiOS-build,wipeiOSBuild, et al in one commit; askSystemiOSPodsCache, wipeSystemiOSPodsCache, getWipeSystemiOSPodsCache, etc in another commit; and so on...)?

Adding this package to react-native 0.60.4 as dev dependency breaks android build

Just the fact that this is added as a dependency breaks the android build. Not sure why. I have a guess that @react-native-community/cli-platform-android/native_modules.gradle searches for modules starting with 'react-native' and tries to add them as native dependencies and then gets confused with this name.

react-native init test2
cd test2
yarn add -D react-native-clean-project
yarn react-native run-android
yarn run v1.17.3
$ /private/tmp/test2/node_modules/.bin/react-native run-android
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 855 file(s) to forward-jetify. Using 8 workers...
info JS server already running.
info Installing the app...
Starting a Gradle Daemon, 1 busy and 3 stopped Daemons could not be reused, use --status for details
<-------------> 0% INITIALIZING [6s]
> Evaluating settings <-- GETS STUCK HERE

Add support for monorepo structure with multiple apps

I'm working with an Nx monorepo of React Native apps and would like to modify this tool to support running the global cleanup commands once while running the app-specific cleanup commands once for each app.

I'm prototyping this locally but can send up a PR later this week.

What this generally entails:

  • Creating a clean-project-auto-monorepo plugin definition for react-native-cli
  • Defining 3 sets of cleanup tasks:
    • The global ones which should run first
    • The app-specific ones to run in the middle
    • The global ones which should run last
  • Adding an optional directory argument to the executeTask function which gets passed on as the cwd option for the spawn call so that the app-specific commands get run from within their respective directories.

Adding more commands

Hi,

Internally we have a couple of scripts for cleaning RN projects, and since we were not aware of this project, I mentioned those scripts in react-native-community/releases (link), where it was suggested to me that I should add some of those here :)

Here is C/P of what we are using:

{
    "clear-cache": "npm run clear-xcode-cache && watchman watch-del-all && rm -rf $TMPDIR/react-* && npm cache verify && rm -rf node_modules/ && npm run clear-npm-pod-cache && rm -rf ios/build/ && cd android && ./gradlew clean && cd .. && npm run start-no-cache",
    "clear-xcode-cache": "cd ios && bash ../resetXcode.sh && cd ..",
    "clear-npm-pod-cache": "rm -rf ios/Podfile.lock && rm -rf package-lock.json && npm run npm-pod-install",
    "npm-pod-install": "npm install && npm run pod-install",
    "pod-install": "cd ios/ && pod install && cd ..",
    "start-no-cache": "npm start -- --reset-cache",
}

And here is resetXcode.sh:

#!/bin/sh
killall Xcode
xcrun -k
xcodebuild -alltargets clean
rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang/ModuleCache"
rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang.$(whoami)/ModuleCache"
rm -rf ~/Library/Developer/Xcode/DerivedData/*
rm -rf ~/Library/Caches/com.apple.dt.Xcode/*

As far as I can see from reading this project's code there are actually only 3 differences:

1. deleting Podifle.lock

We are deleting this, and there is no command here for that.

2. deleting package-lock.json

Not sure if it would be a good idea to add this one here, since npm install runs npm ci which requires package-lock.json to be present

3. pod install

There is only pod update command here, and we are using pod install

@pmadruga I can open PR if you think adding either one of these (or all 3) commands to this project would be valuable, so please let me know :)

Why pod install & deleting lock files?

We are using this approach because we, as a team, agreed to "lock" versions in package.json, ie. we don't allow either ~ or ^ when installing deps. This way we are sure that everyone in the team has "the same stuff"

So when running pod install without Pofile.lock, as far as I am understanding Pods docs, it is basically same as pod update

For pods not listed in the Podfile.lock yet, it searches for the version that matches what is described in the Podfile (like in pod 'MyPod', '~>1.2')

And if Podile.lockis not deleted it just installs the missing pods :)

When you run pod install, it only resolves dependencies for pods that are not already listed in the Podfile.lock

P.S.

I've double-checked and I think those 3 are only differences, but maybe I missed something.

Getting error on react-native clean-project-auto command 0.64.1

Getting error on react-native clean-project-auto

yarn run v1.22.10
$ react-native clean-project-auto

Executing fully-automated project clean.
Use 'react-native clean-project' for more control
Use `./node_modules/.bin/react-native-clean-project' for total control

Error running 'wipe iOS build artifacts': No matching processes belonging to you were found

โœ…  wipe android build folder task has finished running in 40ms.
โœ…  wipe temporary caches task has finished running in 32ms.
โœ…  npm ci task has finished running in 15ms.
โœ…  watchman cache clear (if watchman is installed) task has finished running in 66ms.
โœ…  wipe user iOS Pods cache task has finished running in 506ms.
Error running 'clean android project': 

Error running 'clean android project': FAILURE: Build failed with an exception.

* Where:

Error running 'clean android project': Script '/Users/kailashuniyal/Desktop/cwings-delivery-app/node_modules/react-native-unimodules/gradle.groovy' line: 34

* What went wrong:

Error running 'clean android project': A problem occurred evaluating settings 'CwingsDeliveryApp'.
> 
Error running 'clean android project':  (No such file or directory)

* Try:

Error running 'clean android project': Run with --stacktrace
Error running 'clean android project':  option to get the stack trace. Run with 
Error running 'clean android project': --info or --debug option to get more log output. Run with --scan
Error running 'clean android project':  to get full insights.


Error running 'clean android project': * Get more help at https://help.gradle.org


Error running 'clean android project': BUILD FAILED in 6s

โŒ  Command 'clean android project' failed with code: 1
/Users/kailashuniyal/Desktop/cwings-delivery-app/node_modules/@react-native-community/cli/build/index.js:99
    const message = err.message.replace(/\.$/, '');
                        ^

TypeError: Cannot read property 'message' of undefined
    at handleError (/Users/kailashuniyal/Desktop/cwings-delivery-app/node_modules/@react-native-community/cli/build/index.js:99:25)
    at Command.handleAction (/Users/kailashuniyal/Desktop/cwings-delivery-app/node_modules/@react-native-community/cli/build/index.js:189:7)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
info Fetching system and libraries information...
System:
    OS: macOS 11.4
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 902.64 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.4.2 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 7.19.1 - /usr/local/bin/npm
    Watchman: 2021.06.07.00 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.11.0 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 14.5, DriverKit 20.4, macOS 11.3, tvOS 14.5, watchOS 7.4
    Android SDK:
      API Levels: 28, 29, 30, 31
      Build Tools: 28.0.3, 29.0.2, 30.0.2, 30.0.3, 31.0.0
      System Images: android-29 | Intel x86 Atom_64, android-29 | Google APIs Intel x86 Atom, android-30 | Google APIs Intel x86 Atom, android-31 | Google APIs Intel x86 Atom_64
      Android NDK: Not Found
  IDEs:
    Android Studio: 4.2 AI-202.7660.26.42.7486908
    Xcode: 12.5.1/12E507 - /usr/bin/xcodebuild
  Languages:
    Java: 1.8.0_292 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.1 => 17.0.1 
    react-native: 0.64.1 => 0.64.1 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Windows support? PRs?

Hi, there. Thanks for making this project.
It looks like this project doesn't seem to have Windows support, but this might be easy to add.
Is this something you've given any thought to?
Are you looking for PRs?

Clean Project Auto Failing

Ran clean project auto in my project directory and got this error:

% react-native clean-project-auto

Executing fully-automated project clean.
Use 'react-native clean-project' for more control
Use `./node_modules/.bin/react-native-clean-project' for total control

Error running 'wipe iOS build artifacts': No matching processes belonging to you were found

Error running 'clean android project': /bin/sh: ./gradlew: Permission denied

โŒ  Command 'clean android project' failed with code: 126
/Users/newuser/Desktop/Prototype/node_modules/@react-native-community/cli/build/index.js:99
    const message = err.message.replace(/\.$/, '');
                        ^

TypeError: Cannot read property 'message' of undefined
    at handleError (/Users/newuser/Desktop/Prototype/node_modules/@react-native-community/cli/build/index.js:99:25)
    at Command.handleAction (/Users/newuser/Desktop/Prototype/node_modules/@react-native-community/cli/build/index.js:189:7)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
newuser@Epic-Mac-mini Prototype % 

Getting error message 'No matching processes belonging to you were found'

The wipe iOS build artifacts task is producing an error message on my machine:

Error running 'wipe iOS build artifacts': No matching processes belonging to you were found

It seems the culprit is the following command:

killall Xcode || true

When I run this from the terminal, I get the same error message.

It's worth noting that the task still continues, but its a little strange to see an error message.

hainging on react-native eject

Hello

I upgraded from 3.0.0 to 3.2.1 and tried react-native eject but it hangs on info Generating the Android folder.

Could you please check it ?

Regards

ios clean task does not gracefully fail on linux

Hey @pmadruga ๐Ÿ‘‹ long time no traffic from me here :-)

Today I used patch-package to patch [email protected] for the project I'm working on.

I'm wondering how you would feel about a PR here so that I can use one deep-clean target in package.json with a set of flags that cleans iOS build artifacts, but fails gracefully on non-Darwin machines?

Here is the diff that solved my problem (It is just wrapping the ios task in an if [ \'uname\' == "Darwin" ] really)

diff --git a/node_modules/react-native-clean-project/source/internals/tasks.js b/node_modules/react-native-clean-project/source/internals/tasks.js
index 2d71458..ed53531 100644
--- a/node_modules/react-native-clean-project/source/internals/tasks.js
+++ b/node_modules/react-native-clean-project/source/internals/tasks.js
@@ -2,7 +2,7 @@ const tasks = {
   wipeiOSBuildFolder: {
     name: 'wipe iOS build artifacts',
     command:
-      'rm -rf ios/build && (killall Xcode || true) && xcrun -k && cd ios && xcodebuild -alltargets clean && cd .. && rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang/ModuleCache" && rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang.$(whoami)/ModuleCache" && rm -fr ~/Library/Developer/Xcode/DerivedData/ && rm -fr ~/Library/Caches/com.apple.dt.Xcode/',
+      'if [ `uname` == \'Darwin\' ]; then rm -rf ios/build && (killall Xcode || true) && xcrun -k && cd ios && xcodebuild -alltargets clean && cd .. && rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang/ModuleCache" && rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang.$(whoami)/ModuleCache" && rm -fr ~/Library/Developer/Xcode/DerivedData/ && rm -fr ~/Library/Caches/com.apple.dt.Xcode/; fi',
     args: []
   },
   wipeiOSPodsFolder: {

This issue body was partially generated by patch-package.

Xcode build cache not cleaned

Hello there again good sir :-)

I just had a problem with react-native-firebase after making some changes there that removed whole files. Turns out Xcode has some more secret state that sometimes needs to be blown away, but itโ€™s not done (yet) by react-native-clean-project

invertase/react-native-firebase#2269 (comment)
https://gist.github.com/maciekish/66b6deaa7bc979d0a16c50784e16d697

killall Xcode
xcrun -k
xcodebuild -alltargets clean
rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang/ModuleCache"
rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang.$(whoami)/ModuleCache"
rm -rf ~/Library/Developer/Xcode/DerivedData/*
rm -rf ~/Library/Caches/com.apple.dt.Xcode/*

Lack of default "yes" action is confusing

Typically, when a shell app prompts and displays one of the options in caps, like Y below, that option is the default, and is run when you press enter without providing any input:

Wipe iOS build folder? (Y/n)
๐Ÿšซ Please select 'y' for yes, or 'n' for no.

Error when running: 'teask is not defined'

Hi,

just saw in recent commit (d75098a) to master there is a typo - teask instead of tasks which prevents script from running with the error teask is not defined.

Steps to reproduce:

In terminal: npx react-native-clean-project

cleaning project fails with exit 65 , unable to wipe iOS build artifacts

`
โ„น๏ธ STARTED: "watchman cache clear (if watchman is installed)"
โœ… FINISHED: "watchman cache clear (if watchman is installed)" task has finished running in 102ms.

โ„น๏ธ STARTED: "wipe temporary caches"
โœ… FINISHED: "wipe temporary caches" task has finished running in 21ms.

โ„น๏ธ STARTED: "wipe iOS build artifacts"
/Users/me/repos/MobileApp/node_modules/react-native-clean-project/source/internals/executor.js:40
throw new Error(
^

Error:

Task "wipe iOS build artifacts"
Error: No matching processes belonging to you were found
** CLEAN FAILED **

.
Exit code: 65

at executeTask (/Users/me/repos/Mobile-App/node_modules/react-native-clean-project/source/internals/executor.js:40:11)
at async main (/Users/me/repos/Mobile-App/node_modules/react-native-clean-project/source/index.js:23:5)

Node.js v19.3.0`

Under the hood the wipe iOS build artifacts command is running:

'rm -rf ios/build && (killall Xcode || true) && xcrun -k && cd ios && xcodebuild -alltargets clean && cd .. && rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang/ModuleCache" && rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang.$(whoami)/ModuleCache" && rm -fr ~/Library/Developer/Xcode/DerivedData/ && rm -fr ~/Library/Caches/com.apple.dt.Xcode/',

and output when running this command error:

Could not delete /Users/me/repos/Mobile-App/ios/buildbecause it was not created by the build system. note: To mark this directory as deletable by the build system, runxattr -w com.apple.xcode.CreatedByBuildSystem true /Users/me/repos/Mobile-App/ios/buildwhen it is created. error: Could not delete/Users/me/repos/Mobile-App/ios/buildbecause it was not created by the build system. note: To mark this directory as deletable by the build system, runxattr -w com.apple.xcode.CreatedByBuildSystem true /Users/me/repos/Mobile-App/ios/build when it is created.

Add a CHANGELOG.md file

Thanks for a great library, its really useful to reset the state of a project, especially when fiddly iOS-based build issues occur!

I notice that 4.0.0 has recently been released, but its not immediately obvious why the major version has been bumped. A changelog would really help users such as myself to understand changes before committing to installing a new version.

There is more information on the best practices around changelogs at https://keepachangelog.com. It would be great to see this library adopt a changelog!

Why clean pods cache on windows?

When I run the command npm run clean I get the following error and the process terminates.
My package.json config as:

 "scripts": {
        "clean": "react-native clean-project-auto",
> react-native clean-project-auto


Executing fully-automated project clean.
Use 'react-native clean-project' for more control
Use `./node_modules/.bin/react-native-clean-project' for total control

Error running 'wipe system iOS Pods cache': 'pod' is not recognized as an internal or external command,
operable program or batch file.

โŒ  Command 'wipe system iOS Pods cache' failed with code: 1
C:\SourceCode\test\node_modules\metro-hermes-compiler\src\emhermesc.js:77
          throw ex;
          ^

RuntimeError: abort(TypeError: Cannot read property 'message' of undefined). Build with -s ASSERTIONS=1 for more info.
    at process.abort (C:\SourceCode\test\node_modules\metro-hermes-compiler\src\emhermesc.js:440:13)
    at process.emit (events.js:400:28)
    at processPromiseRejections (internal/process/promises.js:245:33)
    at processTicksAndRejections (internal/process/task_queues.js:96:32)
The system cannot find the path specified.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] clean: `react-native clean-project-auto`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] clean script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

os๏ผš windows 10
version: 3.6.7

Run clean-project-auto without React Native CLI

If clean-project-auto were available through the react-native-clean-project executable (or a separate react-native-clean-project-auto executable), npx could be used without having to install the React Native CLI.

In short, it would be useful to have npx react-native-clean-project --auto.

The `brew upgrade` step fails on an M1 Apple silicon chip

Background

I'm moving an existing react-native project from a x86 machine to a machine with the M1 Apple Silicon chip. All works fine on the x86 machine.

The Issue

On a M1 MacBook Pro, I see the following error message in the terminal (also pictured below) when I run react-native-clean-project and select "Y" on all options:

โ„น๏ธ  STARTED: "brew upgrade"
(node:93071) UnhandledPromiseRejectionWarning: Error:

Task "brew upgrade"
Error: Error: Cannot install under Rosetta 2 in ARM default prefix (/opt/homebrew)!
To rerun under ARM use:
    arch -arm64 brew install ...
To install under x86_64, install Homebrew into /usr/local.
.
Exit code: 1


    at executeTask (/Users/drumsensei/code/mobile-conversations-app/node_modules/react-native-clean-project/source/internals/executor.js:40:11)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async main (/Users/drumsensei/code/mobile-conversations-app/node_modules/react-native-clean-project/source/index.js:47:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:93071) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:93071) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

image

Other useful info

  • This happens if I run it from a locally-installed, up-to-date version or from running npx react-native-clean-project.
  • Running brew upgrade or brew update outside of the react-native-clean-project commands works as expected.

Expected Behavior

Run all commands to their end using commands that work with Apple Silicon.

Brew information

Running which brew shows this in my terminal:

/opt/homebrew/bin/brew

This makes sense for an Apple Silicon installation.

React Native information

React Native info

System

  • OS: macOS 12.6
  • CPU: (10) x64 Apple M1 Max
  • Memory: 603.68 MB / 32.00 GB
  • Shell: 5.8.1 - /bin/zsh

Binaries

  • Node: 14.18.3 - ~/.nvm/versions/node/v14.18.3/bin/node
  • Yarn: 1.22.19 - ~/.nvm/versions/node/v14.18.3/bin/yarn
  • npm: 6.14.15 - ~/.nvm/versions/node/v14.18.3/bin/npm
  • Watchman: 2022.09.12.00 - /opt/homebrew/bin/watchman

Managers

  • CocoaPods: 1.11.3 - /opt/homebrew/bin/pod

SDKs

  • iOS SDK:
    • Platforms: DriverKit 21.4, iOS 16.0, macOS 12.3, tvOS 16.0, watchOS 9.0
  • Android SDK: Not Found

IDEs

  • Android Studio: 2021.2 AI-212.5712.43.2112.8815526
  • Xcode: 14.0/14A309 - /usr/bin/xcodebuild

Languages

  • Java: 11.0.16.1 - /usr/bin/javac

npmPackages

  • @react-native-community/cli: Not Found
  • react: 17.0.1 => 17.0.1
  • react-native: 0.64.3 => 0.64.3
  • react-native-macos: Not Found

npmGlobalPackages

  • react-native: Not Found

Thanks for any help! ๐Ÿ˜‡

Feedback needed for version 4

I'm thinking of rewriting the entire script from the ground up. After having read your feedback, there's a couple of things that I'd like to implement:

  1. This script has to be CI friendly. One command should be enough to wipe the entire application.
  2. (Goes without saying but) existing issues must be solved. Especially the android one.

But the greatest question I'm facing is: should this script be customizable to the point where you'd have something like npm run clean --keep-node_modules --keep-brew --keep-... or should be a complete wipe of the applications artifacts?

When I started version 1, I only wanted to have a single command to reset the application. But then users have different needs and along came the options. I would really like your feedback to rethink this, now that I have more time.

Your thoughts?

(PS: @mikehardy, I would love your input)

Unhandled error in events.js:183

Unhandled error in events.js:183
Sorry that's all the Information I have:

yarn run v1.3.2
$ react-native-clean-project
events.js:183
      throw er; // Unhandled 'error' event
      ^

Error: spawn watchman ENOENT
    at _errnoException (util.js:1022:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:190:19)
    at onErrorNT (internal/child_process.js:372:16)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
    at Function.Module.runMain (module.js:686:11)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

On Windows 10.0.16299 Enterprise

Error: /bin/sh: pod: command not found

As title.

โ„น๏ธ  STARTED: "wipe system iOS Pods cache"
error

Task "wipe system iOS Pods cache"
Error: /bin/sh: pod: command not found
.
Exit code: 127

.
Error:

Task "wipe system iOS Pods cache"
Error: /bin/sh: pod: command not found
.
Exit code: 127

Discussion: require both keep and remove options for flags for non-interactive command line usage

Reading the readme, I was under the impression that: react-native clean-project was interactive and that react-native-clean-project + flags would be non-interactive.

Should we have options supporting both keep & remove something for all flags in order to be able to use it from the command line without interactions?

react-native-clean-project --keep-brew --keep-pods --keep-iOS-build --keep-android-build

example:

const askAndroid = () =>
  new Promise(resolve => {
    if (args.includes('--remove-android-build')) {
      wipeAndroidBuild = true;
      return resolve();
    }
    if (args.includes('--keep-android-build')) {
      wipeAndroidBuild = false;
      return resolve();
    }
    return askQuestion('Wipe android build folder? (Y/n) ', answer => {
      wipeAndroidBuild = checkAnswer(answer, askAndroid, resolve);
    });
  });

Command 'wipe node_modules' failed with code: 1

When I run the command npx react-native clean-project-auto I get the following error and the process terminates.

Error running 'wipe node_modules': rm: 
Error running 'wipe node_modules': fts_read
Error running 'wipe node_modules': : 
Error running 'wipe node_modules': No such file or directory

โŒ  Command 'wipe node_modules' failed with code: 1
/Users/sushrut/Documents/GitHub/Desora-Smoker-RN/node_modules/@react-native-community/cli/build/index.js:99
    const message = err.message.replace(/\.$/, '');
                        ^

TypeError: Cannot read property 'message' of undefined
    at handleError (/Users/sushrut/Documents/GitHub/Desora-Smoker-RN/node_modules/@react-native-community/cli/build/index.js:99:25)
    at Command.handleAction (/Users/sushrut/Documents/GitHub/Desora-Smoker-RN/node_modules/@react-native-community/cli/build/index.js:189:7)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Library Version: 3.6.4
OS: macOS Big Sur 11.5.2

[iOS] App launches after 2-3 minutes on second launch

Versions:
react-native: "0.63.3"
react-native-bootsplash: "^3.1.4"

Hi, I successfully did setup without problem and had successful build. When launching app for the first time, there is no problem, Splash Screen hides in 2-3 seconds. But after killing app and relaunching, Splash Screen get stuck for 2-3 minutes and then calls initial render function of app. I think it is related to native thing, not js side. Here is my AppDelegate.m

Any help/suggestion appreciated. Thanks in advance

#import <UserNotifications/UserNotifications.h>
#import <RNCPushNotificationIOS.h>
#import "AppDelegate.h"

#import "RNFBMessagingModule.h"

#import <FirebaseMessaging.h>
#import <React/RCTLog.h>

#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <React/RCTLinkingManager.h>
#import "RNBootSplash.h" // <- add the header import


#if DEBUG
#ifdef FB_SONARKIT_ENABLED
#import <FlipperKit/FlipperClient.h>
#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
#import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
#import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>
#import <FlipperKitReactPlugin/FlipperKitReactPlugin.h>
static void InitializeFlipper(UIApplication *application) {
  FlipperClient *client = [FlipperClient sharedClient];
  SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults];
  [client addPlugin:[[FlipperKitLayoutPlugin alloc] initWithRootNode:application withDescriptorMapper:layoutDescriptorMapper]];
  [client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]];
  [client addPlugin:[FlipperKitReactPlugin new]];
  [client addPlugin:[[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]];
  [client start];
}
#endif
#endif


@import UIKit;
@import Firebase;

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

  // Disabling notification badge from init ~ Dovik
  application.applicationIconBadgeNumber = 0;

  
  if ([FIRApp defaultApp] == nil) {
     [FIRApp configure];
   }



  #if DEBUG
      #ifdef FB_SONARKIT_ENABLED
        InitializeFlipper(application);
      #endif
  #endif


  NSDictionary *appProperties = [RNFBMessagingModule addCustomPropsToUserProps:nil withLaunchOptions:launchOptions];

  RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
  RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
                                                   moduleName:@"myapp"
                                            initialProperties:appProperties];

  rootView.backgroundColor = [[UIColor alloc] initWithRed:255.0f green:255.0f blue:255.0f alpha:1];
  

  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [UIViewController new];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];


  

 // Define UNUserNotificationCenter
  UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
  center.delegate = self;
   

  [RNBootSplash initWithStoryboard:@"BootSplash" rootView:rootView]; // <- initialization using the storyboard file name

  return YES;
}

// Called when a notification is delivered to a foreground app.
-(void)userNotificationCenter:(UNUserNotificationCenter *)center
      willPresentNotification:(UNNotification *)notification
        withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
{
  // Still call the JS onNotification handler so it can display the new message right away
  NSDictionary *userInfo = notification.request.content.userInfo;
  [RNCPushNotificationIOS didReceiveRemoteNotification:userInfo
                                fetchCompletionHandler:^void (UIBackgroundFetchResult result){}];

  // hide push notification
  completionHandler(UNNotificationPresentationOptionAlert);
}

////Called when a notification is delivered to a foreground app.
//- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler{
//
//    NSDictionary *userInfo = notification.request.content.userInfo;
//    //Foreground
//    NSLog(@"APP_PUSH from foreground %@", userInfo);
//
//   [RNCPushNotificationIOS didReceiveRemoteNotification:userInfo
//   fetchCompletionHandler:^void (UIBackgroundFetchResult result){}];
//   completionHandler(UNNotificationPresentationOptionAlert);
//}








- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
  return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}

// Add this above `@end`:
- (BOOL)application:(UIApplication *)application
   openURL:(NSURL *)url
   options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
  return [RCTLinkingManager application:application openURL:url options:options];
}

// Add this above `@end`:
- (BOOL)application:(UIApplication *)application continueUserActivity:(nonnull NSUserActivity *)userActivity
 restorationHandler:(nonnull void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler
{
 return [RCTLinkingManager application:application
                  continueUserActivity:userActivity
                    restorationHandler:restorationHandler];
}



// Required for the register event.
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
 [RNCPushNotificationIOS didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
  [FIRMessaging messaging].APNSToken = deviceToken;
}
// Required for the notification event. You must call the completion handler after handling the remote notification.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
  [RNCPushNotificationIOS didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];

}
// Required for the registrationError event.
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
 [RNCPushNotificationIOS didFailToRegisterForRemoteNotificationsWithError:error];
}
// Required for localNotification event
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
         withCompletionHandler:(void (^)(void))completionHandler
{
  [RNCPushNotificationIOS didReceiveNotificationResponse:response];
}




@end

Task "update iOS Pods" Error: . Exit code: 1

Running the command npx react-native-clean-project throws

STARTED: "update iOS Pods"
/Users/mstelly/.npm/_npx/7819efec56c4c663/node_modules/react-native-clean-project/source/internals/executor.js:40
    throw new Error(
          ^

Error:

Task "update iOS Pods"
Error: .
Exit code: 1


    at executeTask (/Users/mstelly/.npm/_npx/7819efec56c4c663/node_modules/react-native-clean-project/source/internals/executor.js:40:11)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async main (/Users/mstelly/.npm/_npx/7819efec56c4c663/node_modules/react-native-clean-project/source/index.js:35:5)

React Native Info

System:
  OS: macOS 13.2.1
  CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
  Memory: 175.34 MB / 16.00 GB
  Shell:
    version: 5.8.1
    path: /bin/zsh
Binaries:
  Node:
    version: 16.20.1
    path: ~/.nvm/versions/node/v16.20.1/bin/node
  Yarn:
    version: 3.6.1
    path: ~/.nvm/versions/node/v16.20.1/bin/yarn
  npm:
    version: 8.19.4
    path: ~/.nvm/versions/node/v16.20.1/bin/npm
  Watchman:
    version: 2023.07.24.00
    path: /usr/local/bin/watchman
Managers:
  CocoaPods:
    version: 1.12.1
    path: /usr/local/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 22.2
      - iOS 16.2
      - macOS 13.1
      - tvOS 16.1
      - watchOS 9.1
  Android SDK: Not Found
IDEs:
  Android Studio: 2022.2 AI-222.4459.24.2221.10121639
  Xcode:
    version: 14.2/14C18
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 11.0.19
    path: /Users/mstelly/.jenv/shims/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react: Not Found
  react-native: Not Found
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: Not found
  newArchEnabled: Not found
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found

I haven't found any resolution with a web search. Any ideas why this is occurring and how to resolve it?

Upstream `react-native-clean-project` to React Native CLI's `clean` command

Hey! ๐Ÿ‘‹

I'm maintainer of React Native CLI, and last year we added clean command. react-native-clean-project is great tool, and we would like to upstream all options that RNCP has to clean command, to make it an official solution that will be listed in docs etc.

What do you think about making this tool an official solution? I'll tackle brining all options to RN CLI.

should .hprof files also be deleted?

in the android/ folder there can be .hprof files. they are used for analyzing memory leaks and not needed to build the project, as someone says here:

https://stackoverflow.com/questions/46565273/android-hprof-files-in-project-src

i see that in react-native 0.66, they added this file type to .gitignore:

*.hprof

https://react-native-community.github.io/upgrade-helper/?from=0.65.2&to=0.66.0

i tried opening 1 of these files and it was just over 2 million lines. they may be useful, but i think it could be convenient if they were deleted with this library.

what do other people think?

Should "/vendor/bundle/" also be deleted?

with the release of react-native 0.67 there is now a Gemfile for ruby dependencies. these dependencies are in a new /vendor/bundle/ folder.

while it didnt make it to this release, this folder is supposed to go into .gitignore(there are thousands of files in there so it makes sense). as shown here:

facebook/react-native#32930

since this folder is basically the same as node_modules/ and ios/Pods, i think it would make sense if this package also deleted it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.