clean-rn
Advanced tools
Comparing version 1.0.2 to 1.0.3
90
index.js
#! /usr/bin/env node | ||
const shell = require('shelljs') | ||
const { path } = require('app-root-path') | ||
const fs = require("fs") | ||
const {existsSync, rmSync, readFileSync} = require('fs') | ||
const {homedir} = require('os') | ||
const {join} = require('path') | ||
const {execSync:exec} = require('child_process') | ||
const appRoot = process.cwd() | ||
function error(message) { | ||
console.log('\x1b[31m%s\x1b[0m', message); | ||
} | ||
function hasReactNativeDependency() { | ||
try { | ||
const packageJson = JSON.parse(readFileSync(join(appRoot, 'package.json'), 'utf8')); | ||
const dependencies = packageJson.dependencies || {}; | ||
const devDependencies = packageJson.devDependencies || {}; | ||
const hasReactNativeDependency = dependencies['react-native'] || devDependencies['react-native']; | ||
return hasReactNativeDependency; | ||
} catch (err) { | ||
error( | ||
'Could not parse package.json. make sure your terminal is at the root of your React Native project', | ||
); | ||
return false; | ||
} | ||
} | ||
if (!hasReactNativeDependency()) { | ||
error('This is not a React Native project'); | ||
process.exit(1); | ||
} | ||
function rm(path) { | ||
try { | ||
fs.rmSync(path, { recursive: true, force: true }) | ||
rmSync(path, { recursive: true, force: true }) | ||
} catch (e) { | ||
console.warn(`Failed to delete ${path}, continuing..`) | ||
error(`Failed to delete ${path}, continuing..`) | ||
} | ||
} | ||
console.log(`clean-rn: Cleaning React Native caches for ${path}..`) | ||
console.log(`clean-rn: Cleaning React Native caches for ${appRoot}..`) | ||
// npm | ||
rm(`${path}/node_modules`) | ||
rm(join(appRoot, 'node_modules')) | ||
rm(`${path}/yarn.lock`) | ||
shell.exec("yarn cache clean") | ||
if(existsSync(join(appRoot, 'package-lock.json'))) { | ||
exec('npm cache clean --force') | ||
rm(join(appRoot, 'package-lock.json')) | ||
} else if(existsSync(join(appRoot, 'yarn.lock'))) { | ||
exec('yarn cache clean') | ||
rm(join(appRoot, 'yarn.lock')) | ||
} else if(existsSync(join(appRoot, 'pnpm-lock.yaml'))) { | ||
exec('pnpm store prune') | ||
rm(join(appRoot, 'pnpm-lock.yaml')) | ||
} | ||
rm(`${path}/package-lock.json`) | ||
shell.exec("npm cache clean --force") | ||
// android | ||
rm(`${path}/android/.gradle`) | ||
rm(`${path}/android/.idea`) | ||
rm(`${path}/android/.cxx`) | ||
rm(`${path}/android/build`) | ||
rm(`${path}/android/app/build`) | ||
rm(`${path}/android/app/.cxx`) | ||
rm(`$HOME/.gradle/caches`) | ||
shell.exec("./android/gradlew cleanBuildCache") | ||
const androidPaths=[ | ||
'.gradle', | ||
'.idea', | ||
'.cxx', | ||
'build', | ||
'build', | ||
join('app', 'build'), | ||
join('app', '.cxx'), | ||
] | ||
androidPaths.forEach((p) => rm(join(appRoot, 'android', p))) | ||
exec(join(appRoot, 'android', 'gradlew --stop')) // stop gradle daemon | ||
rm(join(homedir(), '.gradle', 'caches')) | ||
exec(join(appRoot, 'android', 'gradlew clean')) | ||
// ios | ||
rm(`${path}/ios/build`) | ||
rm(`${path}/ios/Pods`) | ||
rm(`${path}/ios/DerivedData`) | ||
console.log("Cleaned everything! Run:\n - yarn/npm i\n - cd ios && pod repo update && pod update\n..to reinstall everything!") | ||
const iosPaths=[ | ||
'build', | ||
'Pods', | ||
'Podfile.lock', | ||
'DerivedData', | ||
] | ||
iosPaths.forEach((p) => rm(join(appRoot, 'ios', p))) | ||
console.log('Cleaned everything! Run:\n - yarn/npm i\n - cd ios && pod repo update && pod update\n..to reinstall everything!') |
{ | ||
"name": "clean-rn", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Clean all React Native caches in your project.", | ||
@@ -33,7 +33,3 @@ "main": "index.js", | ||
}, | ||
"homepage": "https://github.com/mrousavy/clean-rn#readme", | ||
"dependencies": { | ||
"app-root-path": "^3.1.0", | ||
"shelljs": "^0.8.5" | ||
} | ||
"homepage": "https://github.com/mrousavy/clean-rn#readme" | ||
} |
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
4187
0
70
1
- Removedapp-root-path@^3.1.0
- Removedshelljs@^0.8.5
- Removedapp-root-path@3.1.0(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedglob@7.2.3(transitive)
- Removedhasown@2.0.2(transitive)
- Removedinflight@1.0.6(transitive)
- Removedinherits@2.0.4(transitive)
- Removedinterpret@1.4.0(transitive)
- Removedis-core-module@2.13.1(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedonce@1.4.0(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedpath-parse@1.0.7(transitive)
- Removedrechoir@0.6.2(transitive)
- Removedresolve@1.22.8(transitive)
- Removedshelljs@0.8.5(transitive)
- Removedsupports-preserve-symlinks-flag@1.0.0(transitive)
- Removedwrappy@1.0.2(transitive)