Skip to content

Commit ad6710f

Browse files
authored
Basic bun integration (#1108)
* initial bun integration * fixing integration tests * fixing integration tests * fixing integration tests * adding invoker properties * bun install * fix log output * update bun integration test to version 1.0.10
1 parent fc8b9a1 commit ad6710f

File tree

16 files changed

+686
-0
lines changed

16 files changed

+686
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ Tools and property to enable skipping
547547
* npm `-Dskip.npm`
548548
* yarn `-Dskip.yarn`
549549
* bower `-Dskip.bower`
550+
* bun `-Dskip.bun`
550551
* grunt `-Dskip.grunt`
551552
* gulp `-Dskip.gulp`
552553
* jspm `-Dskip.jspm`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
invoker.os.family = !windows, unix, mac

frontend-maven-plugin/src/it/bun-integration/package-lock.json

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "example",
3+
"version": "0.0.1",
4+
"dependencies": {
5+
"classnames": "^2.3.2"
6+
},
7+
"scripts": {
8+
"prebuild": "npm install"
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>com.github.eirslett</groupId>
6+
<artifactId>example</artifactId>
7+
<version>0</version>
8+
<packaging>pom</packaging>
9+
10+
<build>
11+
<plugins>
12+
<plugin>
13+
<groupId>com.github.eirslett</groupId>
14+
<artifactId>frontend-maven-plugin</artifactId>
15+
<!-- NB! Set <version> to the latest released version of frontend-maven-plugin, like in README.md -->
16+
<version>@project.version@</version>
17+
18+
<configuration>
19+
<installDirectory>target</installDirectory>
20+
</configuration>
21+
22+
<executions>
23+
24+
<execution>
25+
<id>install bun runtime</id>
26+
<goals>
27+
<goal>install-bun</goal>
28+
</goals>
29+
<configuration>
30+
<bunVersion>v1.0.10</bunVersion>
31+
</configuration>
32+
</execution>
33+
34+
<execution>
35+
<id>bun install</id>
36+
<goals>
37+
<goal>bun</goal>
38+
</goals>
39+
<!-- Optional configuration which provides for running any npm command -->
40+
<configuration>
41+
<arguments>install</arguments>
42+
</configuration>
43+
</execution>
44+
45+
</executions>
46+
</plugin>
47+
</plugins>
48+
</build>
49+
50+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
assert new File(basedir, 'target/bun').exists(): "Bun was not installed in the custom install directory";
2+
3+
import org.codehaus.plexus.util.FileUtils;
4+
5+
String buildLog = FileUtils.fileRead(new File(basedir, 'build.log'));
6+
7+
assert buildLog.contains('BUILD SUCCESS'): 'build was not successful'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package com.github.eirslett.maven.plugins.frontend.mojo;
2+
3+
import com.github.eirslett.maven.plugins.frontend.lib.FrontendPluginFactory;
4+
import com.github.eirslett.maven.plugins.frontend.lib.ProxyConfig;
5+
import com.github.eirslett.maven.plugins.frontend.lib.TaskRunnerException;
6+
import org.apache.maven.execution.MavenSession;
7+
import org.apache.maven.plugins.annotations.Component;
8+
import org.apache.maven.plugins.annotations.LifecyclePhase;
9+
import org.apache.maven.plugins.annotations.Mojo;
10+
import org.apache.maven.plugins.annotations.Parameter;
11+
import org.apache.maven.settings.crypto.SettingsDecrypter;
12+
import org.sonatype.plexus.build.incremental.BuildContext;
13+
14+
import java.io.File;
15+
import java.util.Collections;
16+
17+
@Mojo(name = "bun", defaultPhase = LifecyclePhase.GENERATE_RESOURCES, threadSafe = true)
18+
public final class BunMojo extends AbstractFrontendMojo {
19+
20+
private static final String NPM_REGISTRY_URL = "npmRegistryURL";
21+
22+
/**
23+
* bun arguments. Default is "install".
24+
*/
25+
@Parameter(defaultValue = "", property = "frontend.bun.arguments", required = false)
26+
private String arguments;
27+
28+
@Parameter(property = "frontend.bun.bunInheritsProxyConfigFromMaven", required = false,
29+
defaultValue = "true")
30+
private boolean bunInheritsProxyConfigFromMaven;
31+
32+
/**
33+
* Registry override, passed as the registry option during npm install if set.
34+
*/
35+
@Parameter(property = NPM_REGISTRY_URL, required = false, defaultValue = "")
36+
private String npmRegistryURL;
37+
38+
@Parameter(property = "session", defaultValue = "${session}", readonly = true)
39+
private MavenSession session;
40+
41+
@Component
42+
private BuildContext buildContext;
43+
44+
@Component(role = SettingsDecrypter.class)
45+
private SettingsDecrypter decrypter;
46+
47+
/**
48+
* Skips execution of this mojo.
49+
*/
50+
@Parameter(property = "skip.bun", defaultValue = "${skip.bun}")
51+
private boolean skip;
52+
53+
@Override
54+
protected boolean skipExecution() {
55+
return this.skip;
56+
}
57+
58+
@Override
59+
public synchronized void execute(FrontendPluginFactory factory) throws TaskRunnerException {
60+
File packageJson = new File(this.workingDirectory, "package.json");
61+
if (this.buildContext == null || this.buildContext.hasDelta(packageJson)
62+
|| !this.buildContext.isIncremental()) {
63+
ProxyConfig proxyConfig = getProxyConfig();
64+
factory.getBunRunner(proxyConfig, getRegistryUrl()).execute(this.arguments,
65+
this.environmentVariables);
66+
} else {
67+
getLog().info("Skipping bun install as package.json unchanged");
68+
}
69+
}
70+
71+
private ProxyConfig getProxyConfig() {
72+
if (this.bunInheritsProxyConfigFromMaven) {
73+
return MojoUtils.getProxyConfig(this.session, this.decrypter);
74+
} else {
75+
getLog().info("bun not inheriting proxy config from Maven");
76+
return new ProxyConfig(Collections.<ProxyConfig.Proxy>emptyList());
77+
}
78+
}
79+
80+
private String getRegistryUrl() {
81+
// check to see if overridden via `-D`, otherwise fallback to pom value
82+
return System.getProperty(NPM_REGISTRY_URL, this.npmRegistryURL);
83+
}
84+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.github.eirslett.maven.plugins.frontend.mojo;
2+
3+
import com.github.eirslett.maven.plugins.frontend.lib.FrontendPluginFactory;
4+
import com.github.eirslett.maven.plugins.frontend.lib.InstallationException;
5+
import com.github.eirslett.maven.plugins.frontend.lib.ProxyConfig;
6+
import org.apache.maven.execution.MavenSession;
7+
import org.apache.maven.plugins.annotations.Component;
8+
import org.apache.maven.plugins.annotations.LifecyclePhase;
9+
import org.apache.maven.plugins.annotations.Mojo;
10+
import org.apache.maven.plugins.annotations.Parameter;
11+
import org.apache.maven.settings.Server;
12+
import org.apache.maven.settings.crypto.SettingsDecrypter;
13+
14+
@Mojo(name = "install-bun", defaultPhase = LifecyclePhase.GENERATE_RESOURCES, threadSafe = true)
15+
public final class InstallBunMojo extends AbstractFrontendMojo {
16+
17+
/**
18+
* The version of Bun to install. IMPORTANT! Most Bun version names start with 'v', for example
19+
* 'v1.0.0'
20+
*/
21+
@Parameter(property = "bunVersion", required = true)
22+
private String bunVersion;
23+
24+
/**
25+
* Server Id for download username and password
26+
*/
27+
@Parameter(property = "serverId", defaultValue = "")
28+
private String serverId;
29+
30+
@Parameter(property = "session", defaultValue = "${session}", readonly = true)
31+
private MavenSession session;
32+
33+
/**
34+
* Skips execution of this mojo.
35+
*/
36+
@Parameter(property = "skip.installbun", alias = "skip.installbun", defaultValue = "${skip.installbun}")
37+
private boolean skip;
38+
39+
@Component(role = SettingsDecrypter.class)
40+
private SettingsDecrypter decrypter;
41+
42+
@Override
43+
protected boolean skipExecution() {
44+
return this.skip;
45+
}
46+
47+
@Override
48+
public void execute(FrontendPluginFactory factory) throws InstallationException {
49+
ProxyConfig proxyConfig = MojoUtils.getProxyConfig(this.session, this.decrypter);
50+
Server server = MojoUtils.decryptServer(this.serverId, this.session, this.decrypter);
51+
if (null != server) {
52+
factory.getBunInstaller(proxyConfig).setBunVersion(this.bunVersion).setUserName(server.getUsername())
53+
.setPassword(server.getPassword()).install();
54+
} else {
55+
factory.getBunInstaller(proxyConfig).setBunVersion(this.bunVersion).install();
56+
}
57+
}
58+
59+
}

frontend-maven-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<goal>install-node-and-npm</goal>
88
<goal>install-node-and-pnpm</goal>
99
<goal>install-node-and-yarn</goal>
10+
<goal>install-bun</goal>
1011
</goals>
1112
</pluginExecutionFilter>
1213
<action>
@@ -25,6 +26,7 @@
2526
<goal>gulp</goal>
2627
<goal>grunt</goal>
2728
<goal>bower</goal>
29+
<goal>bun</goal>
2830
<goal>jspm</goal>
2931
<goal>ember</goal>
3032
<goal>webpack</goal>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.github.eirslett.maven.plugins.frontend.lib;
2+
3+
import org.slf4j.Logger;
4+
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
import java.util.Map;
8+
9+
final class BunExecutor {
10+
private final ProcessExecutor executor;
11+
12+
public BunExecutor(BunExecutorConfig config, List<String> arguments, Map<String, String> additionalEnvironment) {
13+
final String bun = config.getBunPath().getAbsolutePath();
14+
List<String> localPaths = new ArrayList<String>();
15+
localPaths.add(config.getBunPath().getParent());
16+
this.executor = new ProcessExecutor(
17+
config.getWorkingDirectory(),
18+
localPaths,
19+
Utils.prepend(bun, arguments),
20+
config.getPlatform(),
21+
additionalEnvironment);
22+
}
23+
24+
public String executeAndGetResult(final Logger logger) throws ProcessExecutionException {
25+
return executor.executeAndGetResult(logger);
26+
}
27+
28+
public int executeAndRedirectOutput(final Logger logger) throws ProcessExecutionException {
29+
return executor.executeAndRedirectOutput(logger);
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.github.eirslett.maven.plugins.frontend.lib;
2+
3+
import java.io.File;
4+
5+
public interface BunExecutorConfig {
6+
7+
File getNodePath();
8+
9+
File getBunPath();
10+
11+
File getWorkingDirectory();
12+
13+
Platform getPlatform();
14+
}
15+
16+
final class InstallBunExecutorConfig implements BunExecutorConfig {
17+
18+
private File nodePath;
19+
20+
private final InstallConfig installConfig;
21+
22+
public InstallBunExecutorConfig(InstallConfig installConfig) {
23+
this.installConfig = installConfig;
24+
nodePath = new InstallNodeExecutorConfig(installConfig).getNodePath();
25+
}
26+
27+
@Override
28+
public File getNodePath() {
29+
return nodePath;
30+
}
31+
32+
@Override
33+
public File getBunPath() {
34+
return new File(installConfig.getInstallDirectory() + BunInstaller.INSTALL_PATH);
35+
}
36+
37+
@Override
38+
public File getWorkingDirectory() {
39+
return installConfig.getWorkingDirectory();
40+
}
41+
42+
@Override
43+
public Platform getPlatform() {
44+
return installConfig.getPlatform();
45+
}
46+
}

0 commit comments

Comments
 (0)