Skip to content

Commit

Permalink
Fix enabling pnpm from application.properties (#600)
Browse files Browse the repository at this point in the history
Read vaadin.pnpm.enable from app properties file

Fixes #597

Co-authored-by: Pekka Hyvönen <[email protected]>
  • Loading branch information
Denis and Pekka Hyvönen authored Apr 8, 2020
1 parent 0c5552f commit 307c7fa
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 4 deletions.
3 changes: 0 additions & 3 deletions vaadin-spring-tests/test-spring-boot-only-prepare/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,6 @@
<version>${vaadin.flow.version}</version>
<executions>
<execution>
<configuration>
<pnpmEnable>true</pnpmEnable>
</configuration>
<goals>
<goal>prepare-frontend</goal>
</goals>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
server.port=8888
vaadin.blacklisted-packages=vaadin-spring/target/test-classes
vaadin.pnpm.enable=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2000-2020 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.vaadin.flow.spring.test;

import java.io.File;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;

import com.vaadin.flow.component.AttachEvent;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.function.DeploymentConfiguration;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.server.Constants;

@Route("pnpm-enabled")
public class PnpmEnabledView extends Div {

@Autowired
private Environment env;

@Override
protected void onAttach(AttachEvent attachEvent) {
boolean isPnpm = new File("node_modules/.modules.yaml").exists();
String enableProperty = env.getProperty(
"vaadin." + Constants.SERVLET_PARAMETER_ENABLE_PNPM);
DeploymentConfiguration configuration = getUI().get().getSession()
.getService().getDeploymentConfiguration();
Div checkPnpm = new Div();
checkPnpm.setId("check-pnpm");
checkPnpm.setText(
String.valueOf(Boolean.TRUE.toString().equals(enableProperty)
&& !configuration.isProductionMode()));
Div pnpm = new Div();
pnpm.setId("pnpm");
pnpm.setText(String.valueOf(isPnpm));

add(checkPnpm, pnpm);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2000-2020 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.vaadin.flow.spring.test;

import org.junit.Assert;
import org.junit.Assume;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

public class PnpmEnabledIT extends AbstractSpringTest {

@Override
protected String getTestPath() {
return "/pnpm-enabled";
}

@Test
public void checkPnpm() throws Exception {
open();

WebElement checkPnpm = findElement(By.id("check-pnpm"));
Assume.assumeTrue(Boolean.TRUE.toString().equals(checkPnpm.getText()));

WebElement isPnpm = findElement(By.id("pnpm"));
Assert.assertEquals(Boolean.TRUE.toString(), isPnpm.getText());
}
}
3 changes: 3 additions & 0 deletions vaadin-spring-tests/test-spring-white-list/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@
<version>${vaadin.flow.version}</version>
<executions>
<execution>
<configuration>
<pnpmEnable>true</pnpmEnable>
</configuration>
<goals>
<goal>prepare-frontend</goal>
</goals>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public class SpringServlet extends VaadinServlet {
Constants.SERVLET_PARAMETER_JSBUNDLE,
Constants.SERVLET_PARAMETER_POLYFILLS,
Constants.SERVLET_PARAMETER_STATISTICS_JSON,
Constants.SERVLET_PARAMETER_ENABLE_PNPM,
Constants.DISABLE_WEBJARS, Constants.SERVLET_PARAMETER_BROTLI,
Constants.LOAD_ES5_ADAPTERS,
Constants.USE_ORIGINAL_FRONTEND_RESOURCES,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,8 @@ public Enumeration<String> getInitParameterNames() {
* the ServletRegistrationBean to get servlet parameters from
* @param servletClass
* the class to look for properties defined with annotations
* @param appContext
* the ApplicationContext
* @return a DeploymentConfiguration instance
*/
public static DeploymentConfiguration createDeploymentConfiguration(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void deploymentConfigurationPropertiesAreKnown()

// Check that we have added all other constants as parameters (except
// those we know)
Assert.assertEquals(43, constantsCopy.size());
Assert.assertEquals(42, constantsCopy.size());

Assert.assertTrue(constantsCopy
.contains(Constants.REQUIRED_ATMOSPHERE_RUNTIME_VERSION));
Expand Down

0 comments on commit 307c7fa

Please sign in to comment.