Skip to content

Commit b50fcaf

Browse files
authored
fix: workaround for NPM configuration cache (#2390 fixes #2372)
2 parents f77aead + feaac90 commit b50fcaf

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

CHANGES.md

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ This document is intended for Spotless developers.
1010
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`).
1111

1212
## [Unreleased]
13+
### Fixed
14+
* Node.JS-based tasks now work with the configuration cache ([#2372](https://github.com/diffplug/spotless/issues/2372))
1315

1416
## [3.0.1] - 2025-01-07
1517
### Fixed

lib/src/main/java/com/diffplug/spotless/npm/NpmPathResolver.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2024 DiffPlug
2+
* Copyright 2020-2025 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717

1818
import java.io.File;
1919
import java.io.Serializable;
20+
import java.util.ArrayList;
2021
import java.util.List;
2122
import java.util.Optional;
2223

@@ -35,7 +36,9 @@ public NpmPathResolver(File explicitNpmExecutable, File explicitNodeExecutable,
3536
this.explicitNpmExecutable = explicitNpmExecutable;
3637
this.explicitNodeExecutable = explicitNodeExecutable;
3738
this.explicitNpmrcFile = explicitNpmrcFile;
38-
this.additionalNpmrcLocations = List.copyOf(additionalNpmrcLocations);
39+
// We must not use an immutable list (e.g. List.copyOf) here, because immutable lists cannot be restored
40+
// from Gradle’s serialisation. See https://github.com/diffplug/spotless/issues/2372
41+
this.additionalNpmrcLocations = new ArrayList<>(additionalNpmrcLocations);
3942
}
4043

4144
/**

plugin-gradle/CHANGES.md

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`).
44

55
## [Unreleased]
6+
### Fixed
7+
* Node.JS-based tasks now work with the configuration cache ([#2372](https://github.com/diffplug/spotless/issues/2372))
68

79
## [7.0.1] - 2025-01-07
810
### Fixed

plugin-gradle/src/test/java/com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2024 DiffPlug
2+
* Copyright 2016-2025 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -177,4 +177,15 @@ void useNpmNextToConfiguredNodePluginFromNodeGradlePlugin() throws Exception {
177177
throw e;
178178
}
179179
}
180+
181+
@Test
182+
public void supportsConfigurationCache() throws Exception {
183+
setFile("build.gradle").toResource("com/diffplug/gradle/spotless/NpmTestsWithoutNpmInstallationTest_gradle_node_plugin_example_1.gradle");
184+
setFile("test.ts").toResource("npm/prettier/config/typescript.dirty");
185+
BuildResult spotlessApply = gradleRunner()
186+
.withGradleVersion(GradleVersionSupport.STABLE_CONFIGURATION_CACHE.version)
187+
.withArguments("--stacktrace", "--configuration-cache", "spotlessApply").build();
188+
Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL");
189+
assertFile("test.ts").sameAsResource("npm/prettier/config/typescript.configfile_prettier_2.clean");
190+
}
180191
}

0 commit comments

Comments
 (0)