Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ public class Options implements Serializable {
*/
private List<String> postinstallPackages = new ArrayList<>();

/**
* Npm packages to exclude from running postinstall scripts.
*/
private List<String> excludePostinstallPackages = new ArrayList<>();

private FeatureFlags featureFlags;

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

/**
* Sets the npm packages to exclude from running {@code postinstall} for.
* <p>
* Entries here are removed from the built-in default postinstall list (e.g.
* {@code esbuild}, {@code @vaadin/vaadin-usage-statistics}) as well as from
* any additional packages added via {@link #withPostinstallPackages(List)}.
*
* @param excludePostinstallPackages
* the npm packages to exclude from postinstall
* @return the builder, for chaining
*/
public Options withExcludePostinstallPackages(
List<String> excludePostinstallPackages) {
this.excludePostinstallPackages = excludePostinstallPackages;
return this;
}

/**
* Get the npm folder used for this build.
*
Expand Down Expand Up @@ -925,6 +947,10 @@ public List<String> getPostinstallPackages() {
return postinstallPackages;
}

public List<String> getExcludePostinstallPackages() {
return excludePostinstallPackages;
}

/**
* Set to true to skip dev bundle build in case a dev bundle exists.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ private void runNpmInstall() throws ExecutionFailedException {
postinstallPackages.add("esbuild");
postinstallPackages.add("@vaadin/vaadin-usage-statistics");
postinstallPackages.addAll(options.getPostinstallPackages());
postinstallPackages.removeAll(options.getExcludePostinstallPackages());

for (String postinstallPackage : postinstallPackages) {
File packageJsonFile = getPackageJsonForModule(postinstallPackage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,23 @@ void runPnpmInstall_postInstall_runForDefinedAdditionalPackages()
"Postinstall for 'foo' was not run");
}

@Test
void runPnpmInstall_postInstall_excludedBuiltinPackageIsSkipped()
throws ExecutionFailedException, IOException {
setupPostinstallPackages();
options.withExcludePostinstallPackages(
List.of("@vaadin/vaadin-usage-statistics"));
TaskRunNpmInstall task = createTask();
task.execute();

assertFalse(
new File(
new File(options.getNodeModulesFolder(),
"@vaadin/vaadin-usage-statistics"),
"postinstall-file.txt").exists(),
"Postinstall for '@vaadin/vaadin-usage-statistics' should have been skipped");
}

// https://github.com/vaadin/flow/issues/17663
@Test
@Timeout(30)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,15 @@ public class BuildDevBundleMojo extends AbstractMojo
@Parameter(property = "npm.postinstallPackages", defaultValue = "")
private List<String> postinstallPackages;

/**
* Npm packages to exclude from running post install scripts.
* <p>
* Used to skip built-in entries (e.g. {@code esbuild}) when their
* postinstall step is known to fail or is not needed.
*/
@Parameter(property = "npm.excludePostinstallPackages", defaultValue = "")
private List<String> excludePostinstallPackages;

@Parameter(property = InitParameters.REACT_ENABLE, defaultValue = "true")
private boolean reactEnable;

Expand Down Expand Up @@ -516,6 +525,11 @@ public List<String> postinstallPackages() {
return postinstallPackages;
}

@Override
public List<String> excludePostinstallPackages() {
return excludePostinstallPackages;
}

@Override
public boolean isFrontendHotdeploy() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ internal class GradlePluginAdapter private constructor(
override fun postinstallPackages(): List<String> =
config.postinstallPackages.get()

override fun excludePostinstallPackages(): List<String> =
config.excludePostinstallPackages.get()

override fun isFrontendHotdeploy(): Boolean = config.frontendHotdeploy.get()

override fun ciBuild(): Boolean = config.ciBuild.get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ internal class PrepareFrontendInputProperties(
fun getPostInstallPackages(): ListProperty<String> =
config.postinstallPackages

@Input
fun getExcludePostInstallPackages(): ListProperty<String> =
config.excludePostinstallPackages

@Input
fun getFrontendHotdeploy(): Provider<Boolean> = config.frontendHotdeploy

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,13 @@ public abstract class VaadinFlowPluginExtension @Inject constructor(private val
*/
public abstract val postinstallPackages: ListProperty<String>

/**
* Defines the npm packages to exclude from running postinstall scripts.
* Used to skip built-in entries (e.g. `esbuild`) when their postinstall
* step is known to fail or is not needed.
*/
public abstract val excludePostinstallPackages: ListProperty<String>

public val classpathFilter: ClasspathFilter = ClasspathFilter()

/**
Expand Down Expand Up @@ -568,6 +575,10 @@ public class PluginEffectiveConfiguration(
extension.postinstallPackages
.convention(listOf())

public val excludePostinstallPackages: ListProperty<String> =
extension.excludePostinstallPackages
.convention(listOf())

public val classpathFilter: ClasspathFilter = extension.classpathFilter

public val processResourcesTaskName: Property<String> =
Expand Down Expand Up @@ -744,6 +755,7 @@ public class PluginEffectiveConfiguration(
"resourceOutputDirectory=${resourceOutputDirectory.get()}, " +
"projectBuildDir=${projectBuildDir.get()}, " +
"postinstallPackages=${postinstallPackages.get()}, " +
"excludePostinstallPackages=${excludePostinstallPackages.get()}, " +
"sourceSetName=${sourceSetName.get()}, " +
"dependencyScope=${dependencyScope.get()}, " +
"processResourcesTaskName=${processResourcesTaskName.get()}, " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,15 @@ public abstract class FlowModeAbstractMojo extends AbstractMojo
@Parameter(property = "vaadin.npm.postinstallPackages", defaultValue = "")
private List<String> postinstallPackages;

/**
* Npm packages to exclude from running post install scripts.
* <p>
* Used to skip built-in entries (e.g. {@code esbuild}) when their
* postinstall step is known to fail or is not needed.
*/
@Parameter(property = "vaadin.npm.excludePostinstallPackages", defaultValue = "")
private List<String> excludePostinstallPackages;

/**
* Parameter to control if frontend development server should be used in
* development mode or not.
Expand Down Expand Up @@ -710,6 +719,11 @@ public List<String> postinstallPackages() {
return postinstallPackages;
}

@Override
public List<String> excludePostinstallPackages() {
return excludePostinstallPackages;
}

@Override
public boolean isFrontendHotdeploy() {
if (frontendHotdeploy != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ void setup() throws Exception {
Paths.get(projectBase.toString(), "target").toString());
ReflectionUtils.setVariableValueInObject(mojo, "postinstallPackages",
Collections.emptyList());
ReflectionUtils.setVariableValueInObject(mojo,
"excludePostinstallPackages", Collections.emptyList());
Mockito.doReturn(
Set.of(jarResourcesSource.getParentFile().getParentFile()))
.when(mojo).getJarFiles();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,8 @@ public static void runNodeUpdater(PluginAdapterBuild adapter,
.withNodeDownloadRoot(nodeDownloadRootURI)
.setJavaResourceFolder(adapter.javaResourceFolder())
.withPostinstallPackages(adapter.postinstallPackages())
.withExcludePostinstallPackages(
adapter.excludePostinstallPackages())
.withCiBuild(adapter.ciBuild())
.withForceProductionBuild(adapter.forceProductionBuild())
.withReact(adapter.isReactEnabled())
Expand Down Expand Up @@ -440,6 +442,8 @@ public static void runDevBuildNodeUpdater(PluginAdapterBuild adapter)
.withNodeDownloadRoot(nodeDownloadRootURI)
.setJavaResourceFolder(adapter.javaResourceFolder())
.withPostinstallPackages(adapter.postinstallPackages())
.withExcludePostinstallPackages(
adapter.excludePostinstallPackages())
.withBundleBuild(true)
.skipDevBundleBuild(adapter.skipDevBundleBuild())
.withCompressBundle(adapter.compressBundle())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,15 @@ default File frontendOutputDirectory() {
*/
List<String> postinstallPackages();

/**
* Npm packages to exclude from running postinstall scripts. Removes
* matching entries from the built-in defaults and from any packages added
* via {@link #postinstallPackages()}.
*
* @return a list of packages to exclude
*/
List<String> excludePostinstallPackages();

boolean isFrontendHotdeploy();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,13 @@ public class InitParameters implements Serializable {
*/
public static final String ADDITIONAL_POSTINSTALL_PACKAGES = "npm.postinstallPackages";

/**
* Packages to exclude from running postinstall scripts. Used to skip
* built-in entries (e.g. {@code esbuild}) when their postinstall step is
* known to fail or is not needed.
*/
public static final String EXCLUDE_POSTINSTALL_PACKAGES = "npm.excludePostinstallPackages";

/**
* Configuration name for enabling development using the frontend
* development server instead of using an application bundle.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ public static DevModeHandler initDevModeHandler(Set<Class<?>> classes,
InitParameters.ADDITIONAL_POSTINSTALL_PACKAGES, "")
.split(",");

String[] excludePostinstallPackages = config.getStringProperty(
InitParameters.EXCLUDE_POSTINSTALL_PACKAGES, "").split(",");

String frontendGeneratedFolderName = config.getStringProperty(
PROJECT_FRONTEND_GENERATED_DIR_TOKEN,
Paths.get(frontendFolder.getPath(), FrontendUtils.GENERATED)
Expand Down Expand Up @@ -303,6 +306,8 @@ public static DevModeHandler initDevModeHandler(Set<Class<?>> classes,
.withProductionMode(config.isProductionMode())
.withPostinstallPackages(
Arrays.asList(additionalPostinstallPackages))
.withExcludePostinstallPackages(
Arrays.asList(excludePostinstallPackages))
.withFrontendHotdeploy(
mode == Mode.DEVELOPMENT_FRONTEND_LIVERELOAD)
.withBundleBuild(mode == Mode.DEVELOPMENT_BUNDLE)
Expand Down
Loading