Skip to content

Commit

Permalink
fix: support bun 1.2 lock file (#20900)
Browse files Browse the repository at this point in the history
  • Loading branch information
tepi authored Jan 24, 2025
1 parent 69a1986 commit 711a36c
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 8 additions & 3 deletions flow-server/src/main/java/com/vaadin/flow/server/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,25 @@ public final class Constants implements Serializable {
public static final String PACKAGE_JSON = "package.json";

/**
* Name of the <code>npm</code> version locking ile.
* Name of the <code>npm</code> version locking file.
*/
public static final String PACKAGE_LOCK_JSON = "package-lock.json";

/**
* Name of the <code>pnpm</code> version locking ile.
* Name of the <code>pnpm</code> version locking file.
*/
public static final String PACKAGE_LOCK_YAML = "pnpm-lock.yaml";

/**
* Name of the <code>bun</code> version locking ile.
* Name of the <code>bun</code> version locking file.
*/
public static final String PACKAGE_LOCK_BUN = "bun.lockb";

/**
* Name of the <code>bun</code> version locking file, starting from bun 1.2.
*/
public static final String PACKAGE_LOCK_BUN_1_2 = "bun.lock";

/**
* Target folder constant.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class TaskCleanFrontendFiles implements FallibleCommand {
private List<String> 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<File> existingFiles = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}

0 comments on commit 711a36c

Please sign in to comment.