Skip to content

Commit 763fbfe

Browse files
committed
Add .nvmrc
1 parent 2952bd3 commit 763fbfe

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/main/java/com/diffplug/webtools/node/NodePlugin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ public class NodePlugin implements Plugin<Project> {
4242

4343
public static class Extension {
4444
private final Project project;
45+
private final SetupCleanupNode setup = new SetupCleanupNode();
4546

4647
public Extension(Project project) {
4748
this.project = Objects.requireNonNull(project);
48-
}
4949

50-
public final SetupCleanupNode setup = new SetupCleanupNode();
50+
}
5151

5252
public TaskProvider<?> npm_run(String name, Action<Task> taskConfig) {
5353
return project.getTasks().register("npm_run_" + name, NpmRunTask.class, task -> {

src/main/java/com/diffplug/webtools/node/SetupCleanupNode.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,39 @@
2020
import com.github.eirslett.maven.plugins.frontend.lib.ProxyConfig;
2121
import com.github.eirslett.maven.plugins.frontend.lib.TaskRunnerException;
2222
import java.io.File;
23+
import java.io.IOException;
2324
import java.io.Serializable;
25+
import java.nio.charset.StandardCharsets;
2426
import java.nio.file.Files;
2527
import java.util.Collections;
2628

2729
class SetupCleanupNode implements Serializable {
30+
private static String nvmRc(File file) throws IOException {
31+
String str = new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8).trim();
32+
return "v" + str;
33+
}
34+
35+
private static File findNvmRc(File projectDir) {
36+
File nvmRc = new File(projectDir, ".nvmrc");
37+
if (nvmRc.exists()) {
38+
return nvmRc;
39+
}
40+
nvmRc = new File(projectDir.getParentFile(), ".nvmrc");
41+
if (nvmRc.exists()) {
42+
return nvmRc;
43+
}
44+
throw new IllegalArgumentException("Could not find .nvmrc in " + projectDir + " or its parent.");
45+
}
46+
2847
public String nodeVersion;
2948
public String npmVersion;
3049
private File workingDir, installDir;
3150
@SuppressWarnings("unused") // used for serialized equality
3251
private byte[] packageLockJson;
3352

3453
public void start(File projectDir) throws Exception {
54+
nodeVersion = nvmRc(findNvmRc(projectDir));
55+
npmVersion = "provided";
3556
workingDir = projectDir;
3657
installDir = new File(projectDir, "build/node-install");
3758
packageLockJson = Files.readAllBytes(workingDir.toPath().resolve("package-lock.json"));

0 commit comments

Comments
 (0)