Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic bun integration #1108

Merged
merged 9 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ Tools and property to enable skipping
* npm `-Dskip.npm`
* yarn `-Dskip.yarn`
* bower `-Dskip.bower`
* bun `-Dskip.bun`
* grunt `-Dskip.grunt`
* gulp `-Dskip.gulp`
* jspm `-Dskip.jspm`
Expand Down
1 change: 1 addition & 0 deletions frontend-maven-plugin/src/it/bun-integration/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.os.family = !windows, unix, mac
27 changes: 27 additions & 0 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.

10 changes: 10 additions & 0 deletions frontend-maven-plugin/src/it/bun-integration/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "example",
"version": "0.0.1",
"dependencies": {
"classnames": "^2.3.2"
},
"scripts": {
"prebuild": "npm install"
}
}
50 changes: 50 additions & 0 deletions frontend-maven-plugin/src/it/bun-integration/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.github.eirslett</groupId>
<artifactId>example</artifactId>
<version>0</version>
<packaging>pom</packaging>

<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<!-- NB! Set <version> to the latest released version of frontend-maven-plugin, like in README.md -->
<version>@project.version@</version>

<configuration>
<installDirectory>target</installDirectory>
</configuration>

<executions>

<execution>
<id>install bun runtime</id>
<goals>
<goal>install-bun</goal>
</goals>
<configuration>
<bunVersion>v1.0.1</bunVersion>
</configuration>
</execution>

<execution>
<id>bun install</id>
<goals>
<goal>bun</goal>
</goals>
<!-- Optional configuration which provides for running any npm command -->
<configuration>
<arguments>install</arguments>
</configuration>
</execution>

</executions>
</plugin>
</plugins>
</build>

</project>
7 changes: 7 additions & 0 deletions frontend-maven-plugin/src/it/bun-integration/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
assert new File(basedir, 'target/bun').exists(): "Bun was not installed in the custom install directory";

import org.codehaus.plexus.util.FileUtils;

String buildLog = FileUtils.fileRead(new File(basedir, 'build.log'));

assert buildLog.contains('BUILD SUCCESS'): 'build was not successful'
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package com.github.eirslett.maven.plugins.frontend.mojo;

import com.github.eirslett.maven.plugins.frontend.lib.FrontendPluginFactory;
import com.github.eirslett.maven.plugins.frontend.lib.ProxyConfig;
import com.github.eirslett.maven.plugins.frontend.lib.TaskRunnerException;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.settings.crypto.SettingsDecrypter;
import org.sonatype.plexus.build.incremental.BuildContext;

import java.io.File;
import java.util.Collections;

@Mojo(name = "bun", defaultPhase = LifecyclePhase.GENERATE_RESOURCES, threadSafe = true)
public final class BunMojo extends AbstractFrontendMojo {

private static final String NPM_REGISTRY_URL = "npmRegistryURL";

/**
* bun arguments. Default is "install".
*/
@Parameter(defaultValue = "", property = "frontend.bun.arguments", required = false)
private String arguments;

@Parameter(property = "frontend.bun.bunInheritsProxyConfigFromMaven", required = false,
defaultValue = "true")
private boolean bunInheritsProxyConfigFromMaven;

/**
* Registry override, passed as the registry option during npm install if set.
*/
@Parameter(property = NPM_REGISTRY_URL, required = false, defaultValue = "")
private String npmRegistryURL;

@Parameter(property = "session", defaultValue = "${session}", readonly = true)
private MavenSession session;

@Component
private BuildContext buildContext;

@Component(role = SettingsDecrypter.class)
private SettingsDecrypter decrypter;

/**
* Skips execution of this mojo.
*/
@Parameter(property = "skip.bun", defaultValue = "${skip.bun}")
private boolean skip;

@Override
protected boolean skipExecution() {
return this.skip;
}

@Override
public synchronized void execute(FrontendPluginFactory factory) throws TaskRunnerException {
File packageJson = new File(this.workingDirectory, "package.json");
if (this.buildContext == null || this.buildContext.hasDelta(packageJson)
|| !this.buildContext.isIncremental()) {
ProxyConfig proxyConfig = getProxyConfig();
factory.getBunRunner(proxyConfig, getRegistryUrl()).execute(this.arguments,
this.environmentVariables);
} else {
getLog().info("Skipping bun install as package.json unchanged");
}
}

private ProxyConfig getProxyConfig() {
if (this.bunInheritsProxyConfigFromMaven) {
return MojoUtils.getProxyConfig(this.session, this.decrypter);
} else {
getLog().info("bun not inheriting proxy config from Maven");
return new ProxyConfig(Collections.<ProxyConfig.Proxy>emptyList());
}
}

private String getRegistryUrl() {
// check to see if overridden via `-D`, otherwise fallback to pom value
return System.getProperty(NPM_REGISTRY_URL, this.npmRegistryURL);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.github.eirslett.maven.plugins.frontend.mojo;

import com.github.eirslett.maven.plugins.frontend.lib.FrontendPluginFactory;
import com.github.eirslett.maven.plugins.frontend.lib.InstallationException;
import com.github.eirslett.maven.plugins.frontend.lib.ProxyConfig;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.settings.Server;
import org.apache.maven.settings.crypto.SettingsDecrypter;

@Mojo(name = "install-bun", defaultPhase = LifecyclePhase.GENERATE_RESOURCES, threadSafe = true)
public final class InstallBunMojo extends AbstractFrontendMojo {

/**
* The version of Bun to install. IMPORTANT! Most Bun version names start with 'v', for example
* 'v1.0.0'
*/
@Parameter(property = "bunVersion", required = true)
private String bunVersion;

/**
* Server Id for download username and password
*/
@Parameter(property = "serverId", defaultValue = "")
private String serverId;

@Parameter(property = "session", defaultValue = "${session}", readonly = true)
private MavenSession session;

/**
* Skips execution of this mojo.
*/
@Parameter(property = "skip.installbun", alias = "skip.installbun", defaultValue = "${skip.installbun}")
private boolean skip;

@Component(role = SettingsDecrypter.class)
private SettingsDecrypter decrypter;

@Override
protected boolean skipExecution() {
return this.skip;
}

@Override
public void execute(FrontendPluginFactory factory) throws InstallationException {
ProxyConfig proxyConfig = MojoUtils.getProxyConfig(this.session, this.decrypter);
Server server = MojoUtils.decryptServer(this.serverId, this.session, this.decrypter);
if (null != server) {
factory.getBunInstaller(proxyConfig).setBunVersion(this.bunVersion).setUserName(server.getUsername())
.setPassword(server.getPassword()).install();
} else {
factory.getBunInstaller(proxyConfig).setBunVersion(this.bunVersion).install();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<goal>install-node-and-npm</goal>
<goal>install-node-and-pnpm</goal>
<goal>install-node-and-yarn</goal>
<goal>install-bun</goal>
</goals>
</pluginExecutionFilter>
<action>
Expand All @@ -25,6 +26,7 @@
<goal>gulp</goal>
<goal>grunt</goal>
<goal>bower</goal>
<goal>bun</goal>
<goal>jspm</goal>
<goal>ember</goal>
<goal>webpack</goal>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.github.eirslett.maven.plugins.frontend.lib;

import org.slf4j.Logger;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

final class BunExecutor {
private final ProcessExecutor executor;

public BunExecutor(BunExecutorConfig config, List<String> arguments, Map<String, String> additionalEnvironment) {
final String bun = config.getBunPath().getAbsolutePath();
List<String> localPaths = new ArrayList<String>();
localPaths.add(config.getBunPath().getParent());
this.executor = new ProcessExecutor(
config.getWorkingDirectory(),
localPaths,
Utils.prepend(bun, arguments),
config.getPlatform(),
additionalEnvironment);
}

public String executeAndGetResult(final Logger logger) throws ProcessExecutionException {
return executor.executeAndGetResult(logger);
}

public int executeAndRedirectOutput(final Logger logger) throws ProcessExecutionException {
return executor.executeAndRedirectOutput(logger);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.github.eirslett.maven.plugins.frontend.lib;

import java.io.File;

public interface BunExecutorConfig {

File getNodePath();

File getBunPath();

File getWorkingDirectory();

Platform getPlatform();
}

final class InstallBunExecutorConfig implements BunExecutorConfig {

private File nodePath;

private final InstallConfig installConfig;

public InstallBunExecutorConfig(InstallConfig installConfig) {
this.installConfig = installConfig;
nodePath = new InstallNodeExecutorConfig(installConfig).getNodePath();
}

@Override
public File getNodePath() {
return nodePath;
}

@Override
public File getBunPath() {
return new File(installConfig.getInstallDirectory() + BunInstaller.INSTALL_PATH);
}

@Override
public File getWorkingDirectory() {
return installConfig.getWorkingDirectory();
}

@Override
public Platform getPlatform() {
return installConfig.getPlatform();
}
}
Loading