From 51f0bee2997d8642ce7a7f3cde1b1a243ba247e2 Mon Sep 17 00:00:00 2001 From: Teppo Kurki Date: Fri, 24 Jan 2025 09:08:07 +0200 Subject: [PATCH] fix: support bun 1.2 lock file (#20900) --- .../flow/plugin/base/CleanFrontendUtil.java | 4 +++ .../com/vaadin/flow/server/Constants.java | 11 ++++-- .../frontend/TaskCleanFrontendFiles.java | 2 +- .../server/frontend/TaskUpdateImports.java | 3 +- .../vaadin/flow/testutil/FileTestUtil.java | 34 +++++++++++++++++++ .../vaadin/flow/mixedtest/ui/BunUsedIT.java | 5 +-- 6 files changed, 52 insertions(+), 7 deletions(-) diff --git a/flow-plugins/flow-plugin-base/src/main/java/com/vaadin/flow/plugin/base/CleanFrontendUtil.java b/flow-plugins/flow-plugin-base/src/main/java/com/vaadin/flow/plugin/base/CleanFrontendUtil.java index e59dacfdc61..a029159f751 100644 --- a/flow-plugins/flow-plugin-base/src/main/java/com/vaadin/flow/plugin/base/CleanFrontendUtil.java +++ b/flow-plugins/flow-plugin-base/src/main/java/com/vaadin/flow/plugin/base/CleanFrontendUtil.java @@ -78,6 +78,10 @@ public static void runCleaning(PluginAdapterBase adapter, lockFile = new File(adapter.npmFolder(), Constants.PACKAGE_LOCK_BUN); } + if (!lockFile.exists()) { + lockFile = new File(adapter.npmFolder(), + Constants.PACKAGE_LOCK_BUN_1_2); + } if (!lockFile.exists()) { lockFile = new File(adapter.npmFolder(), Constants.PACKAGE_LOCK_JSON); diff --git a/flow-server/src/main/java/com/vaadin/flow/server/Constants.java b/flow-server/src/main/java/com/vaadin/flow/server/Constants.java index edc8e74af5c..c1f90e74ba1 100644 --- a/flow-server/src/main/java/com/vaadin/flow/server/Constants.java +++ b/flow-server/src/main/java/com/vaadin/flow/server/Constants.java @@ -70,20 +70,25 @@ public final class Constants implements Serializable { public static final String PACKAGE_JSON = "package.json"; /** - * Name of the npm version locking ile. + * Name of the npm version locking file. */ public static final String PACKAGE_LOCK_JSON = "package-lock.json"; /** - * Name of the pnpm version locking ile. + * Name of the pnpm version locking file. */ public static final String PACKAGE_LOCK_YAML = "pnpm-lock.yaml"; /** - * Name of the bun version locking ile. + * Name of the bun version locking file. */ public static final String PACKAGE_LOCK_BUN = "bun.lockb"; + /** + * Name of the bun version locking file, starting from bun 1.2. + */ + public static final String PACKAGE_LOCK_BUN_1_2 = "bun.lock"; + /** * Target folder constant. */ diff --git a/flow-server/src/main/java/com/vaadin/flow/server/frontend/TaskCleanFrontendFiles.java b/flow-server/src/main/java/com/vaadin/flow/server/frontend/TaskCleanFrontendFiles.java index 5c57be5c540..7f473183903 100644 --- a/flow-server/src/main/java/com/vaadin/flow/server/frontend/TaskCleanFrontendFiles.java +++ b/flow-server/src/main/java/com/vaadin/flow/server/frontend/TaskCleanFrontendFiles.java @@ -51,7 +51,7 @@ public class TaskCleanFrontendFiles implements FallibleCommand { private List generatedFiles = List.of(NODE_MODULES, Constants.PACKAGE_JSON, Constants.PACKAGE_LOCK_JSON, Constants.PACKAGE_LOCK_YAML, Constants.PACKAGE_LOCK_BUN, - TaskGenerateTsConfig.TSCONFIG_JSON, + Constants.PACKAGE_LOCK_BUN_1_2, TaskGenerateTsConfig.TSCONFIG_JSON, TaskGenerateTsDefinitions.TS_DEFINITIONS, ".pnpmfile.cjs", ".npmrc", FrontendUtils.VITE_GENERATED_CONFIG, FrontendUtils.VITE_CONFIG); private Set existingFiles = new HashSet<>(); diff --git a/flow-server/src/main/java/com/vaadin/flow/server/frontend/TaskUpdateImports.java b/flow-server/src/main/java/com/vaadin/flow/server/frontend/TaskUpdateImports.java index a57c0a4c1ba..302e67f5ec1 100644 --- a/flow-server/src/main/java/com/vaadin/flow/server/frontend/TaskUpdateImports.java +++ b/flow-server/src/main/java/com/vaadin/flow/server/frontend/TaskUpdateImports.java @@ -84,7 +84,8 @@ private String getAbsentPackagesMessage() { String lockFile; String toolName = TaskRunNpmInstall.getToolName(options); if (options.isEnableBun()) { - lockFile = Constants.PACKAGE_LOCK_BUN; + lockFile = Constants.PACKAGE_LOCK_BUN + "/" + + Constants.PACKAGE_LOCK_BUN_1_2; } else if (options.isEnablePnpm()) { lockFile = Constants.PACKAGE_LOCK_YAML; } else { diff --git a/flow-test-util/src/main/java/com/vaadin/flow/testutil/FileTestUtil.java b/flow-test-util/src/main/java/com/vaadin/flow/testutil/FileTestUtil.java index 8832ef87ae7..a248b8b9599 100644 --- a/flow-test-util/src/main/java/com/vaadin/flow/testutil/FileTestUtil.java +++ b/flow-test-util/src/main/java/com/vaadin/flow/testutil/FileTestUtil.java @@ -32,6 +32,40 @@ public static void waitForFile(File file) { "File " + file.getAbsolutePath() + " does not exist"); } + /** + * Waits for at least one of the given files to be present for up to 5 + * minutes. + * + * @param files + * the file(s) to wait for + */ + public static void waitForFiles(File... files) { + long start = System.currentTimeMillis(); + long timeout = 60 * 5; + + while (System.currentTimeMillis() - start < timeout * 1000) { + for (File file : files) { + if (file.exists()) { + return; + } + } + try { + Thread.sleep(100); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + StringBuilder fileNames = new StringBuilder(); + for (File file : files) { + fileNames.append(file.getName()).append(","); + } + ; + throw new IllegalStateException("None of the files " + + (fileNames.isEmpty() ? "" + : fileNames.substring(0, fileNames.length() - 1)) + + " exist"); + } + /** * Asserts the given file is a directory. * diff --git a/flow-tests/test-frontend/test-bun/src/test/java/com/vaadin/flow/mixedtest/ui/BunUsedIT.java b/flow-tests/test-frontend/test-bun/src/test/java/com/vaadin/flow/mixedtest/ui/BunUsedIT.java index 55f0852a382..105787e3bbb 100644 --- a/flow-tests/test-frontend/test-bun/src/test/java/com/vaadin/flow/mixedtest/ui/BunUsedIT.java +++ b/flow-tests/test-frontend/test-bun/src/test/java/com/vaadin/flow/mixedtest/ui/BunUsedIT.java @@ -11,8 +11,9 @@ public class BunUsedIT { @Test public void bunIsUsed() { - File testPackage = new File(Constants.PACKAGE_LOCK_BUN); - FileTestUtil.waitForFile(testPackage); + File bunLockFile = new File(Constants.PACKAGE_LOCK_BUN); + File bunLockFile1_2 = new File(Constants.PACKAGE_LOCK_BUN_1_2); + FileTestUtil.waitForFiles(bunLockFile, bunLockFile1_2); } }