@@ -38,16 +38,45 @@ public NpmPathResolver(File explicitNpmExecutable, File explicitNodeExecutable,
38
38
this .additionalNpmrcLocations = Collections .unmodifiableList (new ArrayList <>(additionalNpmrcLocations ));
39
39
}
40
40
41
+ /**
42
+ * Finds the npm executable to use.
43
+ * <br>
44
+ * Either the explicit npm executable is returned, or - if an explicit node executable is configured - tries to find
45
+ * the npm executable relative to the node executable.
46
+ * Falls back to looking for npm on the user's system using {@link NpmExecutableResolver}
47
+ *
48
+ * @return the npm executable to use
49
+ * @throws IllegalStateException if no npm executable could be found
50
+ */
41
51
public File resolveNpmExecutable () {
42
- return Optional .ofNullable (this .explicitNpmExecutable )
43
- .orElseGet (() -> NpmExecutableResolver .tryFind ()
44
- .orElseThrow (() -> new IllegalStateException ("Can't automatically determine npm executable and none was specifically supplied!\n \n " + NpmExecutableResolver .explainMessage ())));
52
+ if (this .explicitNpmExecutable != null ) {
53
+ return this .explicitNpmExecutable ;
54
+ }
55
+ if (this .explicitNodeExecutable != null ) {
56
+ File nodeExecutableCandidate = new File (this .explicitNodeExecutable .getParentFile (), NpmExecutableResolver .npmExecutableName ());
57
+ if (nodeExecutableCandidate .canExecute ()) {
58
+ return nodeExecutableCandidate ;
59
+ }
60
+ }
61
+ return NpmExecutableResolver .tryFind ()
62
+ .orElseThrow (() -> new IllegalStateException ("Can't automatically determine npm executable and none was specifically supplied!\n \n " + NpmExecutableResolver .explainMessage ()));
45
63
}
46
64
65
+ /**
66
+ * Finds the node executable to use.
67
+ * <br>
68
+ * Either the explicit node executable is returned, or tries to find the node executable relative to the npm executable
69
+ * found by {@link #resolveNpmExecutable()}.
70
+ * @return the node executable to use
71
+ * @throws IllegalStateException if no node executable could be found
72
+ */
47
73
public File resolveNodeExecutable () {
48
- return Optional .ofNullable (this .explicitNodeExecutable )
49
- .orElseGet (() -> NodeExecutableResolver .tryFindNextTo (resolveNpmExecutable ())
50
- .orElseThrow (() -> new IllegalStateException ("Can't automatically determine node executable and none was specifically supplied!\n \n " + NpmExecutableResolver .explainMessage ())));
74
+ if (this .explicitNodeExecutable != null ) {
75
+ return this .explicitNodeExecutable ;
76
+ }
77
+ File npmExecutable = resolveNpmExecutable ();
78
+ return NodeExecutableResolver .tryFindNextTo (npmExecutable )
79
+ .orElseThrow (() -> new IllegalStateException ("Can't automatically determine node executable and none was specifically supplied!\n \n " + NodeExecutableResolver .explainMessage ()));
51
80
}
52
81
53
82
public String resolveNpmrcContent () {
0 commit comments