Skip to content

Commit

Permalink
Merge branch 'master' into unify-websec
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur- authored Sep 20, 2022
2 parents 1342d81 + 30f1492 commit ebc0d27
Show file tree
Hide file tree
Showing 7 changed files with 212 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ public abstract class NodeUpdater implements FallibleCommand {
private static final String DEP_MAIN_VALUE = "index";
private static final String DEP_VERSION_KEY = "version";
private static final String DEP_VERSION_DEFAULT = "1.0.0";
private static final String ROUTER_VERSION = "1.7.4";
protected static final String POLYMER_VERSION = "3.5.1";

static final String VAADIN_VERSION = "vaadinVersion";

Expand Down Expand Up @@ -387,70 +385,48 @@ private static <T extends JsonValue> T computeIfAbsent(
}

Map<String, String> getDefaultDependencies() {
Map<String, String> defaults = new HashMap<>();

defaults.put("@vaadin/router", ROUTER_VERSION);
return readDependencies("default", "dependencies");
}

defaults.put("@polymer/polymer", POLYMER_VERSION);
private Map<String, String> readDependencies(String id,
String packageJsonKey) {
try {
Map<String, String> map = new HashMap<>();
JsonObject dependencies = readPackageJson(id)
.getObject(packageJsonKey);
for (String key : dependencies.keys()) {
map.put(key, dependencies.getString(key));
}

defaults.put("lit", "2.3.0");
return map;
} catch (IOException e) {
log().error(
"Unable to read " + packageJsonKey + " from '" + id + "'",
e);
return new HashMap<>();
}

// Constructable style sheets is only implemented for chrome,
// polyfill needed for FireFox et.al. at the moment
defaults.put("construct-style-sheets-polyfill", "3.1.0");
}

defaults.put("@vaadin/common-frontend", "0.0.17");
private JsonObject readPackageJson(String id) throws IOException {
try (InputStream packageJson = getClass()
.getResourceAsStream("dependencies/" + id + "/package.json")) {
JsonObject content = Json.parse(
IOUtils.toString(packageJson, StandardCharsets.UTF_8));
return content;
}

return defaults;
}

Map<String, String> getDefaultDevDependencies() {
Map<String, String> defaults = new HashMap<>();

defaults.put("typescript", "4.7.4");

final String WORKBOX_VERSION = "6.5.0";
defaults.putAll(readDependencies("default", "devDependencies"));

if (featureFlags.isEnabled(FeatureFlags.WEBPACK)) {
// Webpack plugins and helpers
defaults.put("esbuild-loader", "2.19.0");
defaults.put("html-webpack-plugin", "4.5.1");
defaults.put("fork-ts-checker-webpack-plugin", "6.2.1");
defaults.put("webpack", "4.46.0");
defaults.put("webpack-cli", "4.10.0");
defaults.put("webpack-dev-server", "4.10.0");
defaults.put("compression-webpack-plugin", "4.0.1");
defaults.put("extra-watch-webpack-plugin", "1.0.3");
defaults.put("webpack-merge", "4.2.2");
defaults.put("css-loader", "5.2.7");
defaults.put("extract-loader", "5.1.0");
defaults.put("lit-css-loader", "0.1.0");
defaults.put("file-loader", "6.2.0");
defaults.put("loader-utils", "2.0.0");
defaults.put("workbox-webpack-plugin", WORKBOX_VERSION);

// Forcing chokidar version for now until new babel version is
// available
// check out https://github.com/babel/babel/issues/11488
defaults.put("chokidar", "^3.5.0");
defaults.putAll(readDependencies("webpack", "devDependencies"));
} else {
// Use Vite
defaults.put("vite", "v3.1.0");
defaults.put("@rollup/plugin-replace", "3.1.0");
defaults.put("rollup-plugin-brotli", "3.1.0");
defaults.put("vite-plugin-checker", "0.4.9");
defaults.put("mkdirp", "1.0.4"); // for application-theme-plugin
defaults.put("workbox-build", WORKBOX_VERSION);

// Dependencies of rollup-plugin-postcss-lit-custom
defaults.put("@rollup/pluginutils", "4.1.0");
defaults.put("transform-ast", "2.4.4");

defaults.putAll(readDependencies("vite", "devDependencies"));
}
defaults.put("workbox-core", WORKBOX_VERSION);
defaults.put("workbox-precaching", WORKBOX_VERSION);
defaults.put("glob", "7.2.3");
defaults.put("async", "3.2.2");

return defaults;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "flow-default-dependencies",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Artur Signell",
"license": "Apache-2.0",
"dependencies": {
"@polymer/polymer": "3.5.1",
"@vaadin/common-frontend": "0.0.17",
"@vaadin/router": "1.7.4",
"construct-style-sheets-polyfill": "3.1.0",
"lit": "2.3.0"
},
"devDependencies": {
"async": "3.2.2",
"glob": "7.2.3",
"typescript": "4.7.4",
"workbox-core": "6.5.0",
"workbox-precaching": "6.5.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "flow-vite-dependencies",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Artur Signell",
"license": "Apache-2.0",
"dependencies": {},
"devDependencies": {
"vite": "v3.1.0",
"@rollup/plugin-replace": "3.1.0",
"rollup-plugin-brotli": "3.1.0",
"vite-plugin-checker": "0.4.9",
"mkdirp": "1.0.4",
"workbox-build": "6.5.0",
"@rollup/pluginutils": "4.1.0",
"transform-ast": "2.4.4"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "flow-webpack-dependencies",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Artur Signell",
"license": "Apache-2.0",
"dependencies": {
},
"devDependencies": {
"esbuild-loader": "2.19.0",
"html-webpack-plugin": "4.5.1",
"fork-ts-checker-webpack-plugin": "6.2.1",
"webpack": "4.46.0",
"webpack-cli": "4.10.0",
"webpack-dev-server": "4.10.0",
"compression-webpack-plugin": "4.0.1",
"extra-watch-webpack-plugin": "1.0.3",
"webpack-merge": "4.2.2",
"css-loader": "5.2.7",
"extract-loader": "5.1.0",
"lit-css-loader": "0.1.0",
"file-loader": "6.2.0",
"loader-utils": "2.0.0",
"workbox-webpack-plugin": "6.5.0",
"chokidar": "^3.5.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand All @@ -37,6 +39,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.vaadin.experimental.Feature;
import com.vaadin.experimental.FeatureFlags;
import com.vaadin.flow.server.Constants;
import com.vaadin.flow.server.frontend.scanner.ClassFinder;
Expand Down Expand Up @@ -71,17 +74,26 @@ public class NodeUpdaterTest {

private URL url;

private boolean useWebpack = false;

@Before
public void setUp() throws IOException {
url = new URL("file://bar");
npmFolder = temporaryFolder.newFolder();
resourceFolder = temporaryFolder.newFolder();
generatedPath = temporaryFolder.newFolder();
FeatureFlags featureFlags = Mockito.mock(FeatureFlags.class);
Mockito.when(featureFlags.isEnabled(Mockito.any(Feature.class)))
.thenAnswer((query) -> {
if (query.getArgument(0).equals(FeatureFlags.WEBPACK)) {
return useWebpack;
}
return false;
});
finder = Mockito.mock(ClassFinder.class);
nodeUpdater = new NodeUpdater(finder,
Mockito.mock(FrontendDependencies.class), npmFolder,
generatedPath, resourceFolder, TARGET,
Mockito.mock(FeatureFlags.class)) {
generatedPath, resourceFolder, TARGET, featureFlags) {

@Override
public void execute() {
Expand Down Expand Up @@ -135,6 +147,83 @@ public void getGeneratedModules_should_excludeByFileName()
Assert.assertTrue(modules.contains("GENERATED/c.js"));
}

@Test
public void getDefaultDependencies_includesAllDependencies() {
Map<String, String> defaultDeps = nodeUpdater.getDefaultDependencies();
Set<String> expectedDependencies = new HashSet<>();
expectedDependencies.add("@polymer/polymer");
expectedDependencies.add("@vaadin/common-frontend");
expectedDependencies.add("@vaadin/router");
expectedDependencies.add("construct-style-sheets-polyfill");
expectedDependencies.add("lit");

Set<String> actualDependendencies = defaultDeps.keySet();

Assert.assertEquals(expectedDependencies, actualDependendencies);
}

@Test
public void getDefaultDevDependencies_includesAllDependencies_whenUsingVite() {
Map<String, String> defaultDeps = nodeUpdater
.getDefaultDevDependencies();
Set<String> expectedDependencies = getCommonDevDeps();

// Vite
expectedDependencies.add("vite");
expectedDependencies.add("rollup-plugin-brotli");
expectedDependencies.add("@rollup/plugin-replace");
expectedDependencies.add("@rollup/pluginutils");
expectedDependencies.add("vite-plugin-checker");
expectedDependencies.add("mkdirp");
expectedDependencies.add("workbox-build");
expectedDependencies.add("transform-ast");

Set<String> actualDependendencies = defaultDeps.keySet();

Assert.assertEquals(expectedDependencies, actualDependendencies);
}

@Test
public void getDefaultDevDependencies_includesAllDependencies_whenUsingWebpack() {
useWebpack = true;
Map<String, String> defaultDeps = nodeUpdater
.getDefaultDevDependencies();
Set<String> expectedDependencies = getCommonDevDeps();

// Webpack
// Webpack plugins and helpers
expectedDependencies.add("esbuild-loader");
expectedDependencies.add("html-webpack-plugin");
expectedDependencies.add("fork-ts-checker-webpack-plugin");
expectedDependencies.add("webpack");
expectedDependencies.add("webpack-cli");
expectedDependencies.add("webpack-dev-server");
expectedDependencies.add("compression-webpack-plugin");
expectedDependencies.add("extra-watch-webpack-plugin");
expectedDependencies.add("webpack-merge");
expectedDependencies.add("css-loader");
expectedDependencies.add("extract-loader");
expectedDependencies.add("lit-css-loader");
expectedDependencies.add("file-loader");
expectedDependencies.add("loader-utils");
expectedDependencies.add("workbox-webpack-plugin");
expectedDependencies.add("chokidar");

Set<String> actualDependendencies = defaultDeps.keySet();

Assert.assertEquals(expectedDependencies, actualDependendencies);
}

private Set<String> getCommonDevDeps() {
Set<String> expectedDependencies = new HashSet<>();
expectedDependencies.add("typescript");
expectedDependencies.add("workbox-core");
expectedDependencies.add("workbox-precaching");
expectedDependencies.add("glob");
expectedDependencies.add("async");
return expectedDependencies;
}

@Test
public void updateMainDefaultDependencies_polymerVersionIsNull_useDefault() {
JsonObject object = Json.createObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedCondition;

Expand Down Expand Up @@ -45,9 +46,18 @@ protected WebElement getServerCounterStartButton() {
}

public static int getServerCounter(TestBenchTestCase t) {
WebElement serverCounterElem = t
.findElement(By.id(ClientServerCounterUI.SERVER_COUNTER_ID));
return Integer.parseInt(serverCounterElem.getText());
WebDriverException lastException = null;
for (int i = 0; i < 10; i++) {
try {
WebElement serverCounterElem = t.findElement(
By.id(ClientServerCounterUI.SERVER_COUNTER_ID));
return Integer.parseInt(serverCounterElem.getText());
} catch (WebDriverException e) {
lastException = e;
}
}

throw lastException;
}

public static WebElement getServerCounterStartButton(TestBenchTestCase t) {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
<spring.security.version>5.7.2</spring.security.version>
<gwt.version>2.9.0</gwt.version>
<hibernate.validator.version>6.2.4.Final</hibernate.validator.version>
<slf4j.version>2.0.0</slf4j.version>
<slf4j.version>2.0.1</slf4j.version>
<polymer.version>2.6.1</polymer.version>
<jackson.version>2.13.4</jackson.version>
<jackson.databind.version>2.13.4</jackson.databind.version>
Expand Down

0 comments on commit ebc0d27

Please sign in to comment.