Skip to content

Commit

Permalink
Fix: bun windows support
Browse files Browse the repository at this point in the history
  • Loading branch information
lalo-mx authored and eirslett committed Sep 12, 2024
1 parent a7d3b8b commit f39b40c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
invoker.os.family = !windows, unix, mac
invoker.os.family = windows, unix, mac
11 changes: 9 additions & 2 deletions frontend-maven-plugin/src/it/bun-integration/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend-maven-plugin/src/it/bun-integration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<goal>install-bun</goal>
</goals>
<configuration>
<bunVersion>v1.0.10</bunVersion>
<bunVersion>v1.1.27</bunVersion>
</configuration>
</execution>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public interface BunExecutorConfig {

final class InstallBunExecutorConfig implements BunExecutorConfig {

public static final String BUN_WINDOWS = BunInstaller.INSTALL_PATH.replaceAll("/", "\\\\") + "\\bun.exe";
public static final String BUN_DEFAULT = BunInstaller.INSTALL_PATH + "/bun";

private File nodePath;

private final InstallConfig installConfig;
Expand All @@ -31,7 +34,8 @@ public File getNodePath() {

@Override
public File getBunPath() {
return new File(installConfig.getInstallDirectory() + BunInstaller.INSTALL_PATH);
String bunExecutable = getPlatform().isWindows() ? BUN_WINDOWS : BUN_DEFAULT;
return new File(installConfig.getInstallDirectory() + bunExecutable);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@ public void install() throws InstallationException {
if (!this.bunVersion.startsWith("v")) {
this.logger.warn("Bun version does not start with naming convention 'v'.");
}
if (this.config.getPlatform().isWindows()) {
throw new InstallationException("Unable to install bun on windows!");
} else {
installBunDefault();
}
installBunDefault();
}
}
}
Expand Down Expand Up @@ -136,20 +132,24 @@ private void installBunDefault() throws InstallationException {
+ "Please try the build again.", archive.getPath());
archive.delete();
}

throw e;
}

// Search for the bun binary
String bunExecutable = this.config.getPlatform().isWindows() ? "bun.exe" : "bun";
File bunBinary =
new File(getInstallDirectory(), File.separator + createBunTargetArchitecturePath() + File.separator + "bun");
new File(installDirectory, File.separator + createBunTargetArchitecturePath() + File.separator + bunExecutable);
if (!bunBinary.exists()) {
throw new FileNotFoundException(
"Could not find the downloaded bun binary in " + bunBinary);
} else {
File destinationDirectory = getInstallDirectory();
File destinationDirectory = new File(getInstallDirectory(), BunInstaller.INSTALL_PATH);
if (!destinationDirectory.exists()) {
this.logger.info("Creating destination directory {}", destinationDirectory);
destinationDirectory.mkdirs();
}

File destination = new File(destinationDirectory, "bun");
File destination = new File(destinationDirectory, bunExecutable);
this.logger.info("Copying bun binary from {} to {}", bunBinary, destination);
if (destination.exists() && !destination.delete()) {
throw new InstallationException("Could not install Bun: Was not allowed to delete " + destination);
Expand All @@ -165,6 +165,7 @@ private void installBunDefault() throws InstallationException {
throw new InstallationException(
"Could not install Bun: Was not allowed to make " + destination + " executable.");
}
FileUtils.deleteDirectory(bunExtractDirectory);

this.logger.info("Installed bun locally.");
}
Expand All @@ -189,7 +190,7 @@ private String createDownloadUrl() {
private String createBunTargetArchitecturePath() {
OS os = OS.guess();
Architecture architecture = Architecture.guess();
String destOs = os.equals(OS.Linux) ? "linux" : os.equals(OS.Mac) ? "darwin" : null;
String destOs = os.equals(OS.Linux) ? "linux" : os.equals(OS.Mac) ? "darwin" : os.equals(OS.Windows) ? "windows" : null;
String destArc = architecture.equals(Architecture.x64) ? "x64" : architecture.equals(
Architecture.arm64) ? "aarch64" : null;
return String.format("%s-%s-%s", INSTALL_PATH, destOs, destArc);
Expand Down

0 comments on commit f39b40c

Please sign in to comment.