diff --git a/CHANGES.md b/CHANGES.md index 8f6920ca6c..699a54ace8 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -26,6 +26,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( - Bump default `gherkin-utils` version `10.0.0` -> `12.0.2`. ([#2979](https://github.com/diffplug/spotless/pull/2979)) ### Fixed +- Fix race when creating the npm install cache directory. (([#3096](https://github.com/diffplug/spotless/pull/3096)) - GrEclipse no longer emits expected OSGi and nested-jar warnings during initialization. ([#2445](https://github.com/diffplug/spotless/issues/2445)) - `typescript` `prettier()` no longer emits a warning when its parser is already set to `typescript`. ([#3098](https://github.com/diffplug/spotless/pull/3098)) - `VersionCatalogStep` preserves standalone comments at section boundaries and the end of the file. ([#3048](https://github.com/diffplug/spotless/issues/3048)) diff --git a/lib/src/main/java/com/diffplug/spotless/npm/NodeModulesCachingNpmProcessFactory.java b/lib/src/main/java/com/diffplug/spotless/npm/NodeModulesCachingNpmProcessFactory.java index c483e0c1e2..d7ecc0ef7e 100644 --- a/lib/src/main/java/com/diffplug/spotless/npm/NodeModulesCachingNpmProcessFactory.java +++ b/lib/src/main/java/com/diffplug/spotless/npm/NodeModulesCachingNpmProcessFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2025 DiffPlug + * Copyright 2023-2026 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,9 @@ package com.diffplug.spotless.npm; import java.io.File; +import java.io.IOException; +import java.io.UncheckedIOException; +import java.nio.file.Files; import java.util.List; import java.util.Objects; import java.util.UUID; @@ -43,14 +46,12 @@ private NodeModulesCachingNpmProcessFactory(@Nonnull File cacheDir) { this.shadowCopy = new ShadowCopy(this::assertDir); } - private synchronized File assertDir() { - if (cacheDir.exists() && !cacheDir.isDirectory()) { - throw new IllegalArgumentException("Cache dir must be a directory"); - } - if (!cacheDir.exists()) { - if (!cacheDir.mkdirs()) { - throw new IllegalArgumentException("Cache dir could not be created."); - } + private File assertDir() { + try { + Files.createDirectories(cacheDir.toPath()); + } catch (IOException e) { + throw new UncheckedIOException( + "Could not create cache directory: " + cacheDir.getAbsolutePath(), e); } return cacheDir; } diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index 4247f57370..1e241f50f1 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -19,6 +19,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( - We no longer publish a plugin marker for the legacy `com.diffplug.gradle.spotless` id, which has been redirecting to `com.diffplug.spotless` since 4.0. Builds that still request it now fail with `Plugin [id: 'com.diffplug.gradle.spotless'] was not found` instead of the migration message. ([#3086](https://github.com/diffplug/spotless/pull/3086)) ### Fixed +- Fix race when creating the npm install cache directory. (([#3096](https://github.com/diffplug/spotless/pull/3096)) - GrEclipse no longer emits expected OSGi and nested-jar warnings during initialization. ([#2445](https://github.com/diffplug/spotless/issues/2445)) - `typescript` `prettier()` no longer emits a warning when its parser is already set to `typescript`. ([#3098](https://github.com/diffplug/spotless/pull/3098)) - `versionCatalog()` preserves standalone comments at section boundaries and the end of the file. ([#3048](https://github.com/diffplug/spotless/issues/3048)) diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index a0d385a6f0..eba214eb99 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -18,6 +18,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( - Bump default `gherkin-utils` version `10.0.0` -> `12.0.2`. ([#2979](https://github.com/diffplug/spotless/pull/2979)) ### Fixed +- Fix race when creating the npm install cache directory. (([#3096](https://github.com/diffplug/spotless/pull/3096)) - GrEclipse no longer emits expected OSGi and nested-jar warnings during initialization. ([#2445](https://github.com/diffplug/spotless/issues/2445)) - `typescript` `prettier()` no longer emits a warning when its parser is already set to `typescript`. ([#3098](https://github.com/diffplug/spotless/pull/3098)) - `` preserves standalone comments at section boundaries and the end of the file. ([#3048](https://github.com/diffplug/spotless/issues/3048))