Skip to content

Commit c57103a

Browse files
authored
feat: Support using Bun for package installation (#17890)
Bun is faster at installing packages than both npm and pnpm. It works like npm with `--prefer-offline`, which we would want to use but cannot as it does not work in npm (npm fails instead of downloads missing local packages) Limitations: * Bun is never auto installed. It needs to be available on the system * The bun lock file is not included or used from dev bundles
1 parent 4108f70 commit c57103a

35 files changed

Lines changed: 671 additions & 44 deletions

File tree

‎flow-plugins/flow-dev-bundle-plugin/src/main/java/com/vaadin/flow/plugin/maven/BuildDevBundleMojo.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,11 @@ public boolean pnpmEnable() {
357357
return false;
358358
}
359359

360+
@Override
361+
public boolean bunEnable() {
362+
return false;
363+
}
364+
360365
@Override
361366
public boolean useGlobalPnpm() {
362367
return false;

‎flow-plugins/flow-gradle-plugin/src/main/kotlin/com/vaadin/gradle/GradlePluginAdapter.kt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ internal class GradlePluginAdapter(val project: Project, private val isBeforePro
137137

138138
override fun pnpmEnable(): Boolean = extension.pnpmEnable
139139

140+
override fun bunEnable(): Boolean = extension.bunEnable
141+
140142
override fun useGlobalPnpm(): Boolean = extension.useGlobalPnpm
141143

142144
override fun projectBaseDirectory(): Path = project.projectDir.toPath()

‎flow-plugins/flow-gradle-plugin/src/main/kotlin/com/vaadin/gradle/VaadinFlowPluginExtension.kt‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ public open class VaadinFlowPluginExtension(project: Project) {
9090
*/
9191
public var pnpmEnable: Boolean = Constants.ENABLE_PNPM_DEFAULT
9292

93+
/**
94+
* Instructs to use bun for installing npm frontend resources. Default is false.
95+
*
96+
* bun, is a better front-end dependency management option.
97+
* With bun, packages are cached locally by default and linked (instead of
98+
* downloaded) for every project. This results in reduced disk space usage
99+
* and faster recurring builds when compared to npm.
100+
*/
101+
public var bunEnable: Boolean = Constants.ENABLE_BUN_DEFAULT
102+
93103
/**
94104
* Whether the globally installed pnpm tool is used. By default, the
95105
* pinned supported version of pnpm is used, see [FrontendTools
@@ -303,6 +313,11 @@ public open class VaadinFlowPluginExtension(project: Project) {
303313
pnpmEnable = pnpmEnableProperty
304314
}
305315

316+
val bunEnableProperty: Boolean? = project.getBooleanProperty(InitParameters.SERVLET_PARAMETER_ENABLE_BUN)
317+
if (bunEnableProperty != null) {
318+
bunEnable = bunEnableProperty
319+
}
320+
306321
val ciBuildProperty: Boolean? = project.getBooleanProperty(InitParameters.CI_BUILD)
307322
if (ciBuildProperty != null) {
308323
ciBuild = ciBuildProperty
@@ -348,6 +363,7 @@ public open class VaadinFlowPluginExtension(project: Project) {
348363
"frontendResourcesDirectory=$frontendResourcesDirectory, " +
349364
"optimizeBundle=$optimizeBundle, " +
350365
"pnpmEnable=$pnpmEnable, " +
366+
"bunEnable=$bunEnable, " +
351367
"ciBuild=$ciBuild, " +
352368
"forceProductionBuild=$forceProductionBuild, " +
353369
"useGlobalPnpm=$useGlobalPnpm, " +

‎flow-plugins/flow-maven-plugin/src/main/java/com/vaadin/flow/plugin/maven/CleanFrontendMojo.java‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,12 @@ public void execute() throws MojoFailureException {
5959
removeNodeModules();
6060

6161
// Cleanup (p)npm lock file.
62-
File lockFile = new File(npmFolder(), "pnpm-lock.yaml");
62+
File lockFile = new File(npmFolder(), Constants.PACKAGE_LOCK_YAML);
6363
if (!lockFile.exists()) {
64-
lockFile = new File(npmFolder(), "package-lock.json");
64+
lockFile = new File(npmFolder(), Constants.PACKAGE_LOCK_BUN);
65+
}
66+
if (!lockFile.exists()) {
67+
lockFile = new File(npmFolder(), Constants.PACKAGE_LOCK_JSON);
6568
}
6669
if (lockFile.exists()) {
6770
lockFile.delete();

‎flow-plugins/flow-maven-plugin/src/main/java/com/vaadin/flow/plugin/maven/FlowModeAbstractMojo.java‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,13 @@ public abstract class FlowModeAbstractMojo extends AbstractMojo
142142
+ Constants.ENABLE_PNPM_DEFAULT)
143143
private boolean pnpmEnable;
144144

145+
/**
146+
* Instructs to use bun for installing npm frontend resources.
147+
*/
148+
@Parameter(property = InitParameters.SERVLET_PARAMETER_ENABLE_BUN, defaultValue = ""
149+
+ Constants.ENABLE_BUN_DEFAULT)
150+
private boolean bunEnable;
151+
145152
/**
146153
* Instructs to use globally installed pnpm tool or the default supported
147154
* pnpm version.
@@ -382,6 +389,12 @@ public boolean pnpmEnable() {
382389
return pnpmEnable;
383390
}
384391

392+
@Override
393+
public boolean bunEnable() {
394+
395+
return bunEnable;
396+
}
397+
385398
@Override
386399
public boolean useGlobalPnpm() {
387400

‎flow-plugins/flow-plugin-base/src/main/java/com/vaadin/flow/plugin/base/BuildFrontendUtil.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ public static File propagateBuildInfo(PluginAdapterBase adapter) {
250250

251251
buildInfo.put(InitParameters.SERVLET_PARAMETER_ENABLE_PNPM,
252252
adapter.pnpmEnable());
253+
buildInfo.put(InitParameters.SERVLET_PARAMETER_ENABLE_BUN,
254+
adapter.bunEnable());
253255
buildInfo.put(InitParameters.REQUIRE_HOME_NODE_EXECUTABLE,
254256
adapter.requireHomeNodeExec());
255257

@@ -322,6 +324,7 @@ public static void runNodeUpdater(PluginAdapterBuild adapter)
322324
adapter.generateEmbeddableWebComponents())
323325
.withTokenFile(BuildFrontendUtil.getTokenFile(adapter))
324326
.withEnablePnpm(adapter.pnpmEnable())
327+
.withEnableBun(adapter.bunEnable())
325328
.useGlobalPnpm(adapter.useGlobalPnpm())
326329
.withFrontendGeneratedFolder(adapter.generatedTsFolder())
327330
.withHomeNodeExecRequired(adapter.requireHomeNodeExec())
@@ -384,6 +387,7 @@ public static void runDevBuildNodeUpdater(PluginAdapterBuild adapter)
384387
adapter.generateEmbeddableWebComponents())
385388
.withTokenFile(BuildFrontendUtil.getTokenFile(adapter))
386389
.withEnablePnpm(adapter.pnpmEnable())
390+
.withEnableBun(adapter.bunEnable())
387391
.useGlobalPnpm(adapter.useGlobalPnpm())
388392
.withFrontendGeneratedFolder(adapter.generatedTsFolder())
389393
.withHomeNodeExecRequired(adapter.requireHomeNodeExec())
@@ -672,6 +676,7 @@ public static void updateBuildFile(PluginAdapterBuild adapter) {
672676
buildInfo.remove(FRONTEND_TOKEN);
673677
buildInfo.remove(FRONTEND_HOTDEPLOY);
674678
buildInfo.remove(InitParameters.SERVLET_PARAMETER_ENABLE_PNPM);
679+
buildInfo.remove(InitParameters.SERVLET_PARAMETER_ENABLE_BUN);
675680
buildInfo.remove(InitParameters.CI_BUILD);
676681
buildInfo.remove(InitParameters.REQUIRE_HOME_NODE_EXECUTABLE);
677682
buildInfo.remove(

‎flow-plugins/flow-plugin-base/src/main/java/com/vaadin/flow/plugin/base/PluginAdapterBase.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,14 @@ default Lookup createLookup(ClassFinder classFinder) {
216216

217217
boolean pnpmEnable();
218218

219+
/**
220+
* Instructs to use bun for installing npm frontend resources.
221+
*
222+
* @return boolean
223+
*/
224+
225+
boolean bunEnable();
226+
219227
/**
220228
* Instructs to use globally installed pnpm tool or the default supported
221229
* pnpm version.

‎flow-plugins/flow-plugin-base/src/main/java/com/vaadin/flow/plugin/base/PluginAdapterBuild.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public interface PluginAdapterBuild extends PluginAdapterBase {
7070
* Setting this to true will run {@code npm ci} instead of
7171
* {@code npm install} when using npm.
7272
*
73-
* If using pnpm, the installation will be run with
73+
* If using pnpm or bun, the installation will be run with
7474
* {@code --frozen-lockfile} parameter.
7575
*
7676
* This makes sure that the package lock file will not be overwritten.

‎flow-server/src/main/java/com/vaadin/flow/server/AbstractConfiguration.java‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,16 @@ default boolean isPnpmEnabled() {
130130
Constants.ENABLE_PNPM_DEFAULT);
131131
}
132132

133+
/**
134+
* Returns whether bun is enabled or not.
135+
*
136+
* @return {@code true} if enabled, {@code false} if not
137+
*/
138+
default boolean isBunEnabled() {
139+
return getBooleanProperty(InitParameters.SERVLET_PARAMETER_ENABLE_BUN,
140+
Constants.ENABLE_BUN_DEFAULT);
141+
}
142+
133143
/**
134144
* Returns whether globally installed pnpm is used or the default one (see
135145
* {@link com.vaadin.flow.server.frontend.FrontendTools#DEFAULT_PNPM_VERSION}).

‎flow-server/src/main/java/com/vaadin/flow/server/Constants.java‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ public final class Constants implements Serializable {
7777
*/
7878
public static final String PACKAGE_LOCK_YAML = "pnpm-lock.yaml";
7979

80+
/**
81+
* Name of the <code>bun</code> version locking ile.
82+
*/
83+
public static final String PACKAGE_LOCK_BUN = "bun.lockb";
84+
8085
/**
8186
* Target folder constant.
8287
*/
@@ -114,6 +119,11 @@ public final class Constants implements Serializable {
114119
*/
115120
public static final boolean ENABLE_PNPM_DEFAULT = false;
116121

122+
/**
123+
* Constant for whether bun is default or not.
124+
*/
125+
public static final boolean ENABLE_BUN_DEFAULT = false;
126+
117127
/**
118128
* Constant for setting the pinned supported version of pnpm to be used by
119129
* default (see

0 commit comments

Comments
 (0)