Skip to content

Commit 4595517

Browse files
committed
remove clearDirectory function in favor of rimraf
1 parent 0a7a2c2 commit 4595517

File tree

3 files changed

+6
-19
lines changed

3 files changed

+6
-19
lines changed

packages/jest-cli/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"micromatch": "^2.3.11",
2828
"node-notifier": "^5.1.2",
2929
"pify": "^3.0.0",
30+
"rimraf": "^2.5.4",
3031
"slash": "^1.0.0",
3132
"string-length": "^2.0.0",
3233
"strip-ansi": "^4.0.0",

packages/jest-cli/src/cli/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
Console,
1616
clearLine,
1717
createDirectory,
18-
clearDirectory,
1918
validateCLIOptions,
2019
} from 'jest-util';
2120
import {readConfig} from 'jest-config';
@@ -33,6 +32,7 @@ import Runtime from 'jest-runtime';
3332
import TestWatcher from '../test_watcher';
3433
import watch from '../watch';
3534
import yargs from 'yargs';
35+
import rimraf from 'rimraf';
3636

3737
export async function run(maybeArgv?: Argv, project?: Path) {
3838
const argv: Argv = buildArgv(maybeArgv, project);
@@ -71,7 +71,10 @@ export const runCLI = async (
7171

7272
if (argv.clearCache) {
7373
configs.map(config => {
74-
clearDirectory(config.cacheDirectory);
74+
rimraf(config.cacheDirectory, [], () => {
75+
process.stderr.write(`Unable to clear ${config.cacheDirectory}\n`);
76+
process.exit(1);
77+
});
7578
process.stdout.write(`Cleared ${config.cacheDirectory}\n`);
7679
});
7780

packages/jest-util/src/index.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
*/
99

1010
import mkdirp from 'mkdirp';
11-
import fs from 'graceful-fs';
12-
import path from 'path';
1311

1412
import BufferedConsole from './buffered_console';
1513
import clearLine from './clear_line';
@@ -32,26 +30,11 @@ const createDirectory = (path: string) => {
3230
}
3331
};
3432

35-
const clearDirectory = (directoryPath: string) => {
36-
if (fs.existsSync(directoryPath)) {
37-
fs.readdirSync(directoryPath).map(file => {
38-
const filePath = path.join(directoryPath, file);
39-
if (fs.lstatSync(filePath).isDirectory()) {
40-
clearDirectory(filePath);
41-
} else {
42-
fs.unlinkSync(filePath);
43-
}
44-
});
45-
fs.rmdirSync(directoryPath);
46-
}
47-
};
48-
4933
module.exports = {
5034
BufferedConsole,
5135
Console,
5236
FakeTimers,
5337
NullConsole,
54-
clearDirectory,
5538
clearLine,
5639
createDirectory,
5740
formatTestResults,

0 commit comments

Comments
 (0)