Skip to content

Commit 90b87c8

Browse files
vaadin-bottltv
andauthored
feat: add npm.excludePostinstallPackages option (#24421) (CP: 25.1) (#24442)
This PR cherry-picks changes from the original PR #24421 to branch 25.1. --- #### Original PR description > Adds a configuration option to exclude packages from running postinstall scripts. Mirrors the existing npm.postinstallPackages add-list and applies to both the built-in default entries (e.g. esbuild, @vaadin/vaadin-usage-statistics) and any packages added via postinstallPackages. Wired through Options, the Maven and Gradle plugins, and DevModeInitializer. > > Refs #24333 > Co-authored-by: Tomi Virtanen <tltv@vaadin.com>
1 parent c9303ca commit 90b87c8

13 files changed

Lines changed: 118 additions & 0 deletions

File tree

‎flow-build-tools/src/main/java/com/vaadin/flow/server/frontend/Options.java‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ public class Options implements Serializable {
148148
*/
149149
private List<String> postinstallPackages = new ArrayList<>();
150150

151+
/**
152+
* Npm packages to exclude from running postinstall scripts.
153+
*/
154+
private List<String> excludePostinstallPackages = new ArrayList<>();
155+
151156
private FeatureFlags featureFlags;
152157

153158
private boolean frontendHotdeploy = false;
@@ -698,6 +703,23 @@ public Options withPostinstallPackages(List<String> postinstallPackages) {
698703
return this;
699704
}
700705

706+
/**
707+
* Sets the npm packages to exclude from running {@code postinstall} for.
708+
* <p>
709+
* Entries here are removed from the built-in default postinstall list (e.g.
710+
* {@code esbuild}, {@code @vaadin/vaadin-usage-statistics}) as well as from
711+
* any additional packages added via {@link #withPostinstallPackages(List)}.
712+
*
713+
* @param excludePostinstallPackages
714+
* the npm packages to exclude from postinstall
715+
* @return the builder, for chaining
716+
*/
717+
public Options withExcludePostinstallPackages(
718+
List<String> excludePostinstallPackages) {
719+
this.excludePostinstallPackages = excludePostinstallPackages;
720+
return this;
721+
}
722+
701723
/**
702724
* Get the npm folder used for this build.
703725
*
@@ -925,6 +947,10 @@ public List<String> getPostinstallPackages() {
925947
return postinstallPackages;
926948
}
927949

950+
public List<String> getExcludePostinstallPackages() {
951+
return excludePostinstallPackages;
952+
}
953+
928954
/**
929955
* Set to true to skip dev bundle build in case a dev bundle exists.
930956
* <p>

‎flow-build-tools/src/main/java/com/vaadin/flow/server/frontend/TaskRunNpmInstall.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ private void runNpmInstall() throws ExecutionFailedException {
383383
postinstallPackages.add("esbuild");
384384
postinstallPackages.add("@vaadin/vaadin-usage-statistics");
385385
postinstallPackages.addAll(options.getPostinstallPackages());
386+
postinstallPackages.removeAll(options.getExcludePostinstallPackages());
386387

387388
for (String postinstallPackage : postinstallPackages) {
388389
File packageJsonFile = getPackageJsonForModule(postinstallPackage);

‎flow-build-tools/src/test/java/com/vaadin/flow/server/frontend/TaskRunPnpmInstallTest.java‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,23 @@ void runPnpmInstall_postInstall_runForDefinedAdditionalPackages()
354354
"Postinstall for 'foo' was not run");
355355
}
356356

357+
@Test
358+
void runPnpmInstall_postInstall_excludedBuiltinPackageIsSkipped()
359+
throws ExecutionFailedException, IOException {
360+
setupPostinstallPackages();
361+
options.withExcludePostinstallPackages(
362+
List.of("@vaadin/vaadin-usage-statistics"));
363+
TaskRunNpmInstall task = createTask();
364+
task.execute();
365+
366+
assertFalse(
367+
new File(
368+
new File(options.getNodeModulesFolder(),
369+
"@vaadin/vaadin-usage-statistics"),
370+
"postinstall-file.txt").exists(),
371+
"Postinstall for '@vaadin/vaadin-usage-statistics' should have been skipped");
372+
}
373+
357374
// https://github.com/vaadin/flow/issues/17663
358375
@Test
359376
@Timeout(30)

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,15 @@ public class BuildDevBundleMojo extends AbstractMojo
183183
@Parameter(property = "npm.postinstallPackages", defaultValue = "")
184184
private List<String> postinstallPackages;
185185

186+
/**
187+
* Npm packages to exclude from running post install scripts.
188+
* <p>
189+
* Used to skip built-in entries (e.g. {@code esbuild}) when their
190+
* postinstall step is known to fail or is not needed.
191+
*/
192+
@Parameter(property = "npm.excludePostinstallPackages", defaultValue = "")
193+
private List<String> excludePostinstallPackages;
194+
186195
@Parameter(property = InitParameters.REACT_ENABLE, defaultValue = "true")
187196
private boolean reactEnable;
188197

@@ -516,6 +525,11 @@ public List<String> postinstallPackages() {
516525
return postinstallPackages;
517526
}
518527

528+
@Override
529+
public List<String> excludePostinstallPackages() {
530+
return excludePostinstallPackages;
531+
}
532+
519533
@Override
520534
public boolean isFrontendHotdeploy() {
521535
return false;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,9 @@ internal class GradlePluginAdapter private constructor(
276276
override fun postinstallPackages(): List<String> =
277277
config.postinstallPackages.get()
278278

279+
override fun excludePostinstallPackages(): List<String> =
280+
config.excludePostinstallPackages.get()
281+
279282
override fun isFrontendHotdeploy(): Boolean = config.frontendHotdeploy.get()
280283

281284
override fun ciBuild(): Boolean = config.ciBuild.get()

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ internal class PrepareFrontendInputProperties(
143143
fun getPostInstallPackages(): ListProperty<String> =
144144
config.postinstallPackages
145145

146+
@Input
147+
fun getExcludePostInstallPackages(): ListProperty<String> =
148+
config.excludePostinstallPackages
149+
146150
@Input
147151
fun getFrontendHotdeploy(): Provider<Boolean> = config.frontendHotdeploy
148152

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,13 @@ public abstract class VaadinFlowPluginExtension @Inject constructor(private val
236236
*/
237237
public abstract val postinstallPackages: ListProperty<String>
238238

239+
/**
240+
* Defines the npm packages to exclude from running postinstall scripts.
241+
* Used to skip built-in entries (e.g. `esbuild`) when their postinstall
242+
* step is known to fail or is not needed.
243+
*/
244+
public abstract val excludePostinstallPackages: ListProperty<String>
245+
239246
public val classpathFilter: ClasspathFilter = ClasspathFilter()
240247

241248
/**
@@ -556,6 +563,10 @@ public class PluginEffectiveConfiguration(
556563
extension.postinstallPackages
557564
.convention(listOf())
558565

566+
public val excludePostinstallPackages: ListProperty<String> =
567+
extension.excludePostinstallPackages
568+
.convention(listOf())
569+
559570
public val classpathFilter: ClasspathFilter = extension.classpathFilter
560571

561572
public val processResourcesTaskName: Property<String> =
@@ -728,6 +739,7 @@ public class PluginEffectiveConfiguration(
728739
"resourceOutputDirectory=${resourceOutputDirectory.get()}, " +
729740
"projectBuildDir=${projectBuildDir.get()}, " +
730741
"postinstallPackages=${postinstallPackages.get()}, " +
742+
"excludePostinstallPackages=${excludePostinstallPackages.get()}, " +
731743
"sourceSetName=${sourceSetName.get()}, " +
732744
"dependencyScope=${dependencyScope.get()}, " +
733745
"processResourcesTaskName=${processResourcesTaskName.get()}, " +

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,15 @@ public abstract class FlowModeAbstractMojo extends AbstractMojo
247247
@Parameter(property = "npm.postinstallPackages", defaultValue = "")
248248
private List<String> postinstallPackages;
249249

250+
/**
251+
* Npm packages to exclude from running post install scripts.
252+
* <p>
253+
* Used to skip built-in entries (e.g. {@code esbuild}) when their
254+
* postinstall step is known to fail or is not needed.
255+
*/
256+
@Parameter(property = "vaadin.npm.excludePostinstallPackages", defaultValue = "")
257+
private List<String> excludePostinstallPackages;
258+
250259
/**
251260
* Parameter to control if frontend development server should be used in
252261
* development mode or not.
@@ -692,6 +701,11 @@ public List<String> postinstallPackages() {
692701
return postinstallPackages;
693702
}
694703

704+
@Override
705+
public List<String> excludePostinstallPackages() {
706+
return excludePostinstallPackages;
707+
}
708+
695709
@Override
696710
public boolean isFrontendHotdeploy() {
697711
if (frontendHotdeploy != null) {

‎flow-plugins/flow-maven-plugin/src/test/java/com/vaadin/flow/plugin/maven/BuildFrontendMojoTest.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ void setup() throws Exception {
199199
Paths.get(projectBase.toString(), "target").toString());
200200
ReflectionUtils.setVariableValueInObject(mojo, "postinstallPackages",
201201
Collections.emptyList());
202+
ReflectionUtils.setVariableValueInObject(mojo,
203+
"excludePostinstallPackages", Collections.emptyList());
202204
Mockito.doReturn(
203205
Set.of(jarResourcesSource.getParentFile().getParentFile()))
204206
.when(mojo).getJarFiles();

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,8 @@ public static void runNodeUpdater(PluginAdapterBuild adapter,
363363
.withNodeDownloadRoot(nodeDownloadRootURI)
364364
.setJavaResourceFolder(adapter.javaResourceFolder())
365365
.withPostinstallPackages(adapter.postinstallPackages())
366+
.withExcludePostinstallPackages(
367+
adapter.excludePostinstallPackages())
366368
.withCiBuild(adapter.ciBuild())
367369
.withForceProductionBuild(adapter.forceProductionBuild())
368370
.withReact(adapter.isReactEnabled())
@@ -440,6 +442,8 @@ public static void runDevBuildNodeUpdater(PluginAdapterBuild adapter)
440442
.withNodeDownloadRoot(nodeDownloadRootURI)
441443
.setJavaResourceFolder(adapter.javaResourceFolder())
442444
.withPostinstallPackages(adapter.postinstallPackages())
445+
.withExcludePostinstallPackages(
446+
adapter.excludePostinstallPackages())
443447
.withBundleBuild(true)
444448
.skipDevBundleBuild(adapter.skipDevBundleBuild())
445449
.withCompressBundle(adapter.compressBundle())

0 commit comments

Comments
 (0)