-
Notifications
You must be signed in to change notification settings - Fork 900
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add "clean" command #1582
feat: add "clean" command #1582
Conversation
I'm looking at the |
I made it prompt if you omit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works really well! The only thing I'm missing is tests. Would you mind providing some?
packages/cli-clean/src/clean.ts
Outdated
const npm = os.platform() === 'win32' ? 'npm.cmd' : 'npm'; | ||
const yarn = os.platform() === 'win32' ? 'yarn.cmd' : 'yarn'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In other packages, e.g. cli-doctor
we use the execa
package to handle this for us. Mind verifying it's ok and remove the platform checks? Hope this makes it unnecessary for the execute
helper to exist
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing this on Windows now. Will reply once complete.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works on Windows. I also hid the CocoaPods option when on Windows and added hints:
% yarn react-native clean
? Select all caches to clean ›
Instructions:
↑/↓: Highlight option
←/→/[space]: Toggle selection
a: Toggle all
enter/return: Complete answer
◯ android (Android build caches, e.g. Gradle)
◯ cocoapods (CocoaPods cache)
◉ metro (Metro, haste-map caches)
◯ npm (`node_modules` folder in the current package, and optionally verify npm cache)
◉ watchman (Stop Watchman and delete its cache)
◯ yarn (Yarn cache)
After @satya164 comment internally:
Can we uncheck yarn and npm by default? Cache issues are usually related to metro and watchman in my experience as well. |
6fdf626
to
745f0d7
Compare
745f0d7
to
30f92c2
Compare
packages/cli-clean/src/clean.ts
Outdated
name: 'caches', | ||
message: 'Select all caches to clean', | ||
choices: Object.entries(groups).map(([cmd, group]) => ({ | ||
title: `${cmd} (${group.description})`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about dimming the description, so it doesn't clutter the output too much?
title: `${cmd} (${group.description})`, | |
title: `${cmd} ${chalk.dim((${group.description}))}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beauty!
@@ -1,5 +1,6 @@ | |||
import {getLoader} from '@react-native-community/cli-tools'; | |||
import type {Config as CLIConfig} from '@react-native-community/cli-types'; | |||
import chalk from 'chalk'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we'll need to add chalk
to package.json. Hope this fixes the CI that started to fail with weird unrelated error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops 😄
const script = path.basename(gradlew); | ||
await execa( | ||
os.platform() === 'win32' ? script : `./${script}`, | ||
['clean'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small FYI: clean won't work for users on New Architecture due to a bug on AGP that is causing clean
to depend on preBuild
. I agree that ./gradlew clean
would be the correct approach here, but maybe we should not advertise it yet? Or have a isNewArchitectureEnabled
flag inside the CLI to check this and run a rm
?
Summary:
This adds a
clean
command to the CLI for common cleaning operations.Originally contributed by @dennismunene: microsoft/rnx-kit#993
Test Plan:
Test
--help
:By default, prompts the user for caches to remove:
Remove
node_modules
:Clean Gradle cache and
node_modules
: