From b2bbfa43d810255164ef4af977b1a5bb4e46ad13 Mon Sep 17 00:00:00 2001 From: ARAYN7011 <88572149+ARAYN7011@users.noreply.github.com> Date: Sat, 21 Nov 2026 10:14:14 +0530 Subject: [PATCH 1/2] Ignore directories when searching for npm/node executables A directory such as NODE_PATH/npm passes File.canExecute(), so it was picked as the npm executable. Require a regular file. Fixes #3190 Co-Authored-By: Claude Sonnet 5.5 Signed-off-by: ARAYN7011 <88572149+ARAYN7011@users.noreply.github.com> --- CHANGES.md | 2 + .../com/diffplug/spotless/npm/FileFinder.java | 5 +- .../diffplug/spotless/npm/FileFinderTest.java | 55 +++++++++++++++++++ 3 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 testlib/src/test/java/com/diffplug/spotless/npm/FileFinderTest.java diff --git a/CHANGES.md b/CHANGES.md index 34332aecf0..5a3c98ad78 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +- Fix npm/node executable discovery treating a directory (e.g. an `npm` folder inside `NODE_PATH`) as an executable. ([#3190](https://github.com/diffplug/spotless/issues/3190)) ## [4.12.0] - 2026-11-21 ### Changes diff --git a/lib/src/main/java/com/diffplug/spotless/npm/FileFinder.java b/lib/src/main/java/com/diffplug/spotless/npm/FileFinder.java index b1f45a0455..8bed0f557d 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/FileFinder.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/FileFinder.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2025 DiffPlug + * Copyright 2020-2026 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -91,7 +91,8 @@ public FileFinder build() { private static class FileIsExecutableFilter implements Predicate { @Override public boolean test(File file) { - return file.canExecute(); + // a directory is also "executable" (searchable), but is never a valid executable + return file.isFile() && file.canExecute(); } static Predicate executable() { diff --git a/testlib/src/test/java/com/diffplug/spotless/npm/FileFinderTest.java b/testlib/src/test/java/com/diffplug/spotless/npm/FileFinderTest.java new file mode 100644 index 0000000000..65e3832d47 --- /dev/null +++ b/testlib/src/test/java/com/diffplug/spotless/npm/FileFinderTest.java @@ -0,0 +1,55 @@ +/* + * Copyright 2026 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.npm; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +class FileFinderTest { + + @TempDir + Path tempDir; + + @Test + void directoryWithExecutableNameIsNotAnExecutable() throws IOException { + Files.createDirectory(tempDir.resolve("npm")); + + FileFinder finder = FileFinder.finderForExecutableFilename("npm") + .candidateFileInFolder(tempDir.toFile()) + .build(); + + assertThat(finder.tryFind()).isEmpty(); + } + + @Test + void executableFileIsFound() throws IOException { + Path npm = Files.createFile(tempDir.resolve("npm")); + assertThat(npm.toFile().setExecutable(true)).isTrue(); + + FileFinder finder = FileFinder.finderForExecutableFilename("npm") + .candidateFileInFolder(tempDir.toFile()) + .build(); + + assertThat(finder.tryFind()).contains(new File(tempDir.toFile(), "npm")); + } +} From f713fcd78e9bfd32a17923c6607a7a3d262dae18 Mon Sep 17 00:00:00 2001 From: ARAYN7011 <88572149+ARAYN7011@users.noreply.github.com> Date: Sat, 21 Nov 2026 10:14:32 +0530 Subject: [PATCH 2/2] Add changelog entries for plugin-gradle and plugin-maven Co-Authored-By: Claude Sonnet 5.5 Signed-off-by: ARAYN7011 <88572149+ARAYN7011@users.noreply.github.com> --- plugin-gradle/CHANGES.md | 2 ++ plugin-maven/CHANGES.md | 2 ++ 2 files changed, 4 insertions(+) diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 42ba69c572..1151abc9ae 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Fixed +- Fix npm/node executable discovery treating a directory (e.g. an `npm` folder inside `NODE_PATH`) as an executable. ([#3190](https://github.com/diffplug/spotless/issues/3190)) ## [8.12.0] - 2026-11-21 ### Added diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 82cd6b27b0..626f743508 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Fixed +- Fix npm/node executable discovery treating a directory (e.g. an `npm` folder inside `NODE_PATH`) as an executable. ([#3190](https://github.com/diffplug/spotless/issues/3190)) ## [3.12.0] - 2026-11-21 ### Changes