Fail fast and include pakcage.json

This commit is contained in:
2026-01-06 03:40:05 +01:00
parent e886a3600b
commit c67fdb94f2
2 changed files with 22 additions and 16 deletions

11
pom.xml
View File

@@ -128,6 +128,17 @@
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>${project.basedir}</directory>
<includes>
<include>package.json</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>

View File

@@ -62,12 +62,11 @@ public class VersionService {
}
private String resolveClientVersion() {
String packageJsonVersion = getPackageJsonVersion();
if (packageJsonVersion != null && !packageJsonVersion.isBlank()) {
return packageJsonVersion;
try {
return getPackageJsonVersion();
} catch (IOException e) {
throw new IllegalStateException("Client manifest is missing", e);
}
return serverVersion;
}
private String normalizeReleaseVersion(String baseVersion) {
@@ -159,13 +158,12 @@ public class VersionService {
return null;
}
private String getPackageJsonVersion() {
private String getPackageJsonVersion() throws IOException {
Path packageJsonPath = Paths.get("package.json");
if (!Files.exists(packageJsonPath) || !Files.isRegularFile(packageJsonPath)) {
return null;
}
try {
String packageJson = Files.readString(packageJsonPath, StandardCharsets.UTF_8);
Matcher matcher = PACKAGE_VERSION_PATTERN.matcher(packageJson);
if (matcher.find()) {
@@ -174,9 +172,6 @@ public class VersionService {
return version.trim();
}
}
} catch (IOException e) {
LOG.warn("Unable to read version from package.json", e);
}
return null;
}