Skip to content

Commit 641399f

Browse files
committed
chore: replace rimraf with fs-extra
1 parent cfaf95f commit 641399f

File tree

3 files changed

+39
-1700
lines changed

3 files changed

+39
-1700
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
"@expo/metro-config": "^0.1.15",
2525
"chalk": "^4.1.0",
2626
"execa": "^4.0.2",
27+
"fs-extra": "^10.0.0",
2728
"minimist": "^1.2.5",
2829
"open": "^7.0.4",
29-
"rimraf": "^3.0.2",
3030
"source-map-explorer": "^2.4.2"
3131
},
3232
"scripts": {

src/react-native-bundle-visualizer.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/usr/bin/env node
22
const chalk = require('chalk');
3-
const fs = require('fs');
3+
const fs = require('fs-extra');
44
const os = require('os');
5+
const path = require('path');
56
const argv = require('minimist')(process.argv.slice(2));
67
const execa = require('execa');
7-
const rimraf = require('rimraf');
88
const open = require('open');
99
const { explore } = require('source-map-explorer');
1010
const pkgJSON = JSON.parse(fs.readFileSync('./package.json'));
@@ -36,24 +36,25 @@ function getEntryPoint() {
3636
}
3737

3838
// Get (default) arguments
39-
const baseDir = os.tmpdir() + '/react-native-bundle-visualizer';
40-
const tmpDir = baseDir + '/' + getAppName();
39+
const baseDir = path.join(os.tmpdir(), 'react-native-bundle-visualizer');
40+
const tmpDir = path.join(baseDir, getAppName());
41+
const outDir = path.join(tmpDir, 'output');
4142
const entryFile = argv['entry-file'] || getEntryPoint();
4243
const platform = argv.platform || 'ios';
4344
const expoTarget = argv.expo || '';
4445
const dev = argv.dev || false;
4546
const verbose = argv.verbose || false;
4647
const resetCache = argv['reset-cache'] || false;
4748
const bundleOutput =
48-
argv['bundle-output'] || tmpDir + '/' + platform + '.bundle';
49+
argv['bundle-output'] || path.join(tmpDir, platform + '.bundle');
4950
const bundleOutputSourceMap = bundleOutput + '.map';
5051
const format = argv.format || 'html';
51-
const bundleOutputExplorerFile = tmpDir + '/output/explorer.' + format;
52+
const bundleOutputExplorerFile = path.join(outDir, 'explorer.' + format);
5253
const onlyMapped = !!argv['only-mapped'] || false;
5354

5455
// Make sure the temp dir exists
55-
if (!fs.existsSync(baseDir)) fs.mkdirSync(baseDir);
56-
if (!fs.existsSync(tmpDir)) fs.mkdirSync(tmpDir);
56+
fs.ensureDirSync(baseDir);
57+
fs.ensureDirSync(tmpDir);
5758

5859
// Try to obtain the previous file size
5960
let prevBundleSize;
@@ -84,7 +85,7 @@ if (resetCache) {
8485
if (expoTarget) {
8586
process.env.EXPO_TARGET = expoTarget;
8687
commands.push('--config');
87-
commands.push(__dirname + '/expo-metro.config.js');
88+
commands.push(path.join(__dirname, 'expo-metro.config.js'));
8889
}
8990

9091
const bundlePromise = execa('./node_modules/.bin/react-native', commands);
@@ -122,7 +123,7 @@ bundlePromise
122123
);
123124

124125
// Make sure the explorer output dir is removed
125-
if (fs.existsSync(tmpDir + '/output')) rimraf.sync(tmpDir + '/output');
126+
fs.removeSync(outDir);
126127
return explore(
127128
{
128129
code: bundleOutput,

0 commit comments

Comments
 (0)