mirror of
https://github.com/cincheo/jsweet.git
synced 2025-12-15 07:19:22 +00:00
fix testing if executable is installed
This commit is contained in:
parent
c196424c28
commit
98d2081afd
@ -104,10 +104,17 @@ public class ProcessUtil {
|
||||
+ "bin" + File.separator + mainFileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the full path of a global package's JS main file installed with npm.
|
||||
*/
|
||||
public static String getGlobalNpmPackageExecutablePath(String command) {
|
||||
return getGlobalNpmPackageExecutablePath(command, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the full path of a global package's JS main file installed with npm.
|
||||
*/
|
||||
public static String getGlobalNpmPackageExecutablePath(String command) {
|
||||
public static String getGlobalNpmPackageExecutablePath(String command, boolean throwError) {
|
||||
File commandFile = new File(command);
|
||||
if (commandFile.isFile() && commandFile.isAbsolute()) {
|
||||
return command;
|
||||
@ -121,8 +128,13 @@ public class ProcessUtil {
|
||||
}
|
||||
|
||||
logger.info("cannot find " + command + " - searching in " + NPM_DIR.getAbsolutePath());
|
||||
return lookupGlobalNpmPackageExecutablePath(NPM_DIR, command)
|
||||
.orElseThrow(() -> new RuntimeException("Could not locate command " + command));
|
||||
if (throwError) {
|
||||
return lookupGlobalNpmPackageExecutablePath(NPM_DIR, command)
|
||||
.orElseThrow(() -> new RuntimeException("Could not locate command " + command));
|
||||
} else {
|
||||
return lookupGlobalNpmPackageExecutablePath(NPM_DIR, command).get();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -177,7 +189,7 @@ public class ProcessUtil {
|
||||
* Tells if this node command is globally installed.
|
||||
*/
|
||||
public static boolean isExecutableInstalledGloballyWithNpm(String command) {
|
||||
String executablePath = getGlobalNpmPackageExecutablePath(command);
|
||||
String executablePath = getGlobalNpmPackageExecutablePath(command, false);
|
||||
return executablePath != null && new File(executablePath).exists();
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user