Skip to content

Commit aded15e

Browse files
use command-exists instead of manually checking if cmd is avalible
this commit replaces old code that was designed to determine if things like rustup or wasm-gc were installed the new implementation uses the npm package command-exists, which gives us better async, errs, etc
1 parent 2e4855a commit aded15e

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

packages/react-scripts/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-scripts-rust",
3-
"version": "2.0.15",
3+
"version": "2.0.16",
44
"description": "Configuration and scripts for using Rust with Create React App",
55
"repository": "thomashorrobin/create-react-app-rust",
66
"license": "MIT",
@@ -32,6 +32,7 @@
3232
"bfj": "6.1.1",
3333
"case-sensitive-paths-webpack-plugin": "2.1.2",
3434
"chalk": "2.4.1",
35+
"command-exists": "^1.2.8",
3536
"css-loader": "1.0.0",
3637
"dotenv": "6.0.0",
3738
"dotenv-expand": "4.2.0",

packages/react-scripts/scripts/utils/rustUtils.js

+8-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const execSync = require('child_process').execSync;
22
const chalk = require('chalk');
3+
const commandExistsSync = require('command-exists').sync;
34

45
module.exports = {
56
build: () => {
@@ -13,19 +14,14 @@ module.exports = {
1314
console.log(chalk.bold.red('error compiling rust'));
1415
}
1516
},
16-
isRustInstalled: () => {
17-
try {
18-
execSync('rustup show');
19-
return true;
20-
} catch (error) {
21-
return false;
22-
}
23-
},
17+
isRustInstalled: () => commandExistsSync('rustup'),
2418
installRustWebAssemblyTools: () => {
25-
try {
26-
execSync('cargo install wasm-gc', { stdio: 'inherit' });
27-
} catch {
28-
console.log(`${chalk.bold.red('error installing wasm-gc')} please install manually ${chalk.red('cargo install wasm-gc')}')`);
19+
if (!commandExistsSync('wasm-gc')) {
20+
try {
21+
execSync('cargo install wasm-gc', { stdio: 'inherit' });
22+
} catch {
23+
console.log(`${chalk.bold.red('error installing wasm-gc')} please install manually ${chalk.red('cargo install wasm-gc')}')`);
24+
}
2925
}
3026
execSync(
3127
'rustup target add wasm32-unknown-unknown --toolchain nightly',

0 commit comments

Comments
 (0)