fix: workaround for NPM configuration cache (#2390 fixes #2372) · diffplug/spotless@b50fcaf (original) (raw)

File tree

Original file line number Diff line number Diff line change
@@ -10,6 +10,8 @@ This document is intended for Spotless developers.
10 10 We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`).
11 11
12 12 ## [Unreleased]
13 +### Fixed
14 +* Node.JS-based tasks now work with the configuration cache ([#2372](https://github.com/diffplug/spotless/issues/2372))
13 15
14 16 ## [3.0.1] - 2025-01-07
15 17 ### Fixed
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
1 1 /*
2 - * Copyright 2020-2024 DiffPlug
2 + * Copyright 2020-2025 DiffPlug
3 3 *
4 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 5 * you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
17 17
18 18 import java.io.File;
19 19 import java.io.Serializable;
20 +import java.util.ArrayList;
20 21 import java.util.List;
21 22 import java.util.Optional;
22 23
@@ -35,7 +36,9 @@ public NpmPathResolver(File explicitNpmExecutable, File explicitNodeExecutable,
35 36 this.explicitNpmExecutable = explicitNpmExecutable;
36 37 this.explicitNodeExecutable = explicitNodeExecutable;
37 38 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);
39 42 }
40 43
41 44 /**
Original file line number Diff line number Diff line change
@@ -3,6 +3,8 @@
3 3 We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`).
4 4
5 5 ## [Unreleased]
6 +### Fixed
7 +* Node.JS-based tasks now work with the configuration cache ([#2372](https://github.com/diffplug/spotless/issues/2372))
6 8
7 9 ## [7.0.1] - 2025-01-07
8 10 ### Fixed
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
1 1 /*
2 - * Copyright 2016-2024 DiffPlug
2 + * Copyright 2016-2025 DiffPlug
3 3 *
4 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 5 * you may not use this file except in compliance with the License.
@@ -177,4 +177,15 @@ void useNpmNextToConfiguredNodePluginFromNodeGradlePlugin() throws Exception {
177 177 throw e;
178 178 }
179 179 }
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 + }
180 191 }