From 11d2ead7493e54af9bcca3259debd4f735ed1116 Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 5 Jul 2024 12:53:34 -0700 Subject: [PATCH 1/2] Fixed order of npm version detection. --- .../diffplug/webtools/node/NodePlugin.java | 31 +++++++++++++++++-- .../webtools/node/SetupCleanupNode.java | 21 ------------- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/diffplug/webtools/node/NodePlugin.java b/src/main/java/com/diffplug/webtools/node/NodePlugin.java index c2471c5..03be667 100644 --- a/src/main/java/com/diffplug/webtools/node/NodePlugin.java +++ b/src/main/java/com/diffplug/webtools/node/NodePlugin.java @@ -16,6 +16,10 @@ package com.diffplug.webtools.node; import com.github.eirslett.maven.plugins.frontend.lib.ProxyConfig; +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.Collections; import java.util.Objects; import org.gradle.api.Action; @@ -46,12 +50,18 @@ public static class Extension { public Extension(Project project) { this.project = Objects.requireNonNull(project); - } public TaskProvider npm_run(String name, Action taskConfig) { return project.getTasks().register("npm_run_" + name, NpmRunTask.class, task -> { task.taskName = name; + try { + setup.nodeVersion = nvmRc(findNvmRc(project.getProjectDir())); + setup.npmVersion = "provided"; + } catch (IOException e) { + throw new RuntimeException(e); + } + task.getSetup().set(setup); task.getProjectDir().set(project.getProjectDir()); task.getInputs().file("package-lock.json").withPathSensitivity(PathSensitivity.RELATIVE); @@ -91,8 +101,23 @@ public void npmCiRunTask() throws Exception { @Override public void apply(Project project) { - extension = project.getExtensions().create(EXTENSION_NAME, Extension.class, project); + project.getExtensions().create(EXTENSION_NAME, Extension.class, project); + } + + private static String nvmRc(File file) throws IOException { + String str = new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8).trim(); + return "v" + str; } - private Extension extension; + private static File findNvmRc(File projectDir) { + File nvmRc = new File(projectDir, ".nvmrc"); + if (nvmRc.exists()) { + return nvmRc; + } + nvmRc = new File(projectDir.getParentFile(), ".nvmrc"); + if (nvmRc.exists()) { + return nvmRc; + } + throw new IllegalArgumentException("Could not find .nvmrc in " + projectDir + " or its parent."); + } } diff --git a/src/main/java/com/diffplug/webtools/node/SetupCleanupNode.java b/src/main/java/com/diffplug/webtools/node/SetupCleanupNode.java index 9c49565..4bccc36 100644 --- a/src/main/java/com/diffplug/webtools/node/SetupCleanupNode.java +++ b/src/main/java/com/diffplug/webtools/node/SetupCleanupNode.java @@ -20,30 +20,11 @@ import com.github.eirslett.maven.plugins.frontend.lib.ProxyConfig; import com.github.eirslett.maven.plugins.frontend.lib.TaskRunnerException; import java.io.File; -import java.io.IOException; import java.io.Serializable; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.Collections; class SetupCleanupNode implements Serializable { - private static String nvmRc(File file) throws IOException { - String str = new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8).trim(); - return "v" + str; - } - - private static File findNvmRc(File projectDir) { - File nvmRc = new File(projectDir, ".nvmrc"); - if (nvmRc.exists()) { - return nvmRc; - } - nvmRc = new File(projectDir.getParentFile(), ".nvmrc"); - if (nvmRc.exists()) { - return nvmRc; - } - throw new IllegalArgumentException("Could not find .nvmrc in " + projectDir + " or its parent."); - } - public String nodeVersion; public String npmVersion; private File workingDir, installDir; @@ -51,8 +32,6 @@ private static File findNvmRc(File projectDir) { private byte[] packageLockJson; public void start(File projectDir) throws Exception { - nodeVersion = nvmRc(findNvmRc(projectDir)); - npmVersion = "provided"; workingDir = projectDir; installDir = new File(projectDir, "build/node-install"); packageLockJson = Files.readAllBytes(workingDir.toPath().resolve("package-lock.json")); From cddc735c079fbac52fa3e3510b32fc6f2596a34f Mon Sep 17 00:00:00 2001 From: Ned Twigg Date: Fri, 5 Jul 2024 12:53:38 -0700 Subject: [PATCH 2/2] Update changelog. --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db68dc8..c967e62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,9 @@ # Webtools releases ## [Unreleased] +### Fixed +- Fixed order of npm version detection. ## [0.1.0] - 2024-07-05 -First ever release +First release.