Skip to content

Commit

Permalink
chore: add package-lock.json for hybrid apps to dev-bundle
Browse files Browse the repository at this point in the history
A 'hybrid-package-lock.json', containing also Hilla dependencies, is added to the
vaadin-dev-bundle artifact, so that Flow can chose the appropriate lock file based
on the project configuration.

Part of vaadin/flow#19298
  • Loading branch information
mcollovati authored and manolo committed May 10, 2024
1 parent 3d8a138 commit 22a5a06
Show file tree
Hide file tree
Showing 15 changed files with 331 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,7 @@ vaadin-maven-plugin/pom.xml
vaadin-gradle-plugin/pom.xml
vaadin-gradle-plugin/pom*xml
vaadin-platform-javadoc/pom.xml
vaadin-hybrid-dev-bundle/pom.xml
vaadin-dev-bundle/pom.xml
vaadin-prod-bundle/pom.xml
vaadin-prod-bundle/pom-unoptimized.xml
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
<module>vaadin-testbench-junit5</module>
<module>vaadin-spring-boot-starter</module>
<module>vaadin-platform-javadoc</module>
<module>vaadin-hybrid-dev-bundle</module>
<module>vaadin-dev-bundle</module>
<module>vaadin-prod-bundle/pom-unoptimized.xml</module>
<module>vaadin-prod-bundle</module>
Expand Down
1 change: 1 addition & 0 deletions scripts/generateBoms.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ cp scripts/generator/results/vaadin-gradle-plugin-pom.xml vaadin-gradle-plugin/p
cp scripts/generator/results/vaadin-gradle-plugin-portal-pom.xml vaadin-gradle-plugin/pom-portal.xml
cp scripts/generator/results/vaadin-core-versions.json vaadin-core-internal/vaadin-core-versions.json
cp scripts/generator/results/vaadin-versions.json vaadin-internal/vaadin-versions.json
cp scripts/generator/results/vaadin-hybrid-dev-bundle-pom.xml vaadin-hybrid-dev-bundle/pom.xml
cp scripts/generator/results/vaadin-dev-bundle-pom.xml vaadin-dev-bundle/pom.xml
cp scripts/generator/results/vaadin-prod-bundle-pom.xml vaadin-prod-bundle/pom.xml

Expand Down
5 changes: 5 additions & 0 deletions scripts/generator/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ const servletContainersTestsPomFileName = getTemplateFilePath('template-servlet-
const devBundleTemplateFileName = getTemplateFilePath('template-dev-bundle-pom.xml');
const devBundlePomResultFileName = getResultsFilePath('vaadin-dev-bundle-pom.xml');

const hybridDevBundleTemplateFileName = getTemplateFilePath('template-hybrid-dev-bundle-pom.xml');
const hybridDevBundlePomResultFileName = getResultsFilePath('vaadin-hybrid-dev-bundle-pom.xml');

const prodBundleTemplateFileName = getTemplateFilePath('template-prod-bundle-pom.xml');
const prodBundlePomResultFileName = getResultsFilePath('vaadin-prod-bundle-pom.xml');

Expand Down Expand Up @@ -103,6 +106,8 @@ writer.writeProperty(versions, ["hilla"], gradlePortalPluginTemplatePomFileName,
writer.writeProperty(versions, ["flow"], platformJavadocTemplatePomFileName, platformJavadocResultPomFileName);

writer.writeProperty(versions, ["flow", "hilla"], devBundleTemplateFileName, devBundlePomResultFileName);
writer.writeProperty(versions, ["flow", "hilla"], hybridDevBundleTemplateFileName, hybridDevBundlePomResultFileName);
writer.writeProperty(versions, ["flow"], prodBundleTemplateFileName, prodBundlePomResultFileName);
writer.writeMaven(versions, devBundleTemplateFileName, devBundlePomResultFileName);
writer.writeMaven(versions, hybridDevBundleTemplateFileName, hybridDevBundlePomResultFileName);

38 changes: 38 additions & 0 deletions scripts/generator/templates/template-dev-bundle-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
</properties>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>vaadin-hybrid-dev-bundle</artifactId>
<version>${project.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-internal</artifactId>
Expand Down Expand Up @@ -106,6 +112,38 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-hilla-package-lock-to-bundle</id>
<phase>prepare-package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>${project.groupId}</groupId>
<artifactId>vaadin-hybrid-dev-bundle</artifactId>
<version>${project.version}</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>${project.build.directory}/dev-bundle</outputDirectory>
<includes>**/package-lock.json</includes>
<fileMappers>
<org.codehaus.plexus.components.io.filemappers.RegExpFileMapper>
<pattern>^\Qvaadin-dev-bundle/package-lock.json\E</pattern>
<replacement>hybrid-package-lock.json</replacement>
</org.codehaus.plexus.components.io.filemappers.RegExpFileMapper>
</fileMappers>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
Expand Down
171 changes: 171 additions & 0 deletions scripts/generator/templates/template-hybrid-dev-bundle-pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-platform-parent</artifactId>
<version>{{platform}}</version>
</parent>
<artifactId>vaadin-hybrid-dev-bundle</artifactId>
<packaging>jar</packaging>
<name>Vaadin Hybrid Dev Bundle</name>
<description>Vaadin Hybrid Dev Bundle</description>
<url>https://vaadin.com</url>

<distributionManagement>
<repository>
<id>vaadin-prereleases</id>
<url>https://maven.vaadin.com/vaadin-prereleases/</url>
</repository>
</distributionManagement>

<properties>
{{javadeps}}
</properties>

<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-internal</artifactId>
<version>${project.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>hilla-dev</artifactId>
<version>${hilla.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>hilla</artifactId>
<version>${hilla.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-spreadsheet-flow</artifactId>
<version>${vaadin.spreadsheet.version}</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-dev-server</artifactId>
<version>${flow.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>copilot</artifactId>
<version>${copilot.version}</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<excludes>
<exclude>**/*Fake*</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>com.vaadin</groupId>
<artifactId>flow-dev-bundle-plugin</artifactId>
<version>${flow.version}</version>
<executions>
<execution>
<goals>
<goal>build-dev-bundle</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>copy-dev-bundle-to-target</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.outputDirectory}/vaadin-dev-bundle</outputDirectory>
<resources>
<resource>
<directory>${project.build.directory}/dev-bundle</directory>
<excludes>
<exclude>file-routes.json</exclude>
</excludes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<filesets>
<fileset>
<directory>${project.basedir}/src/main/bundles</directory>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<!-- Remove application class file, so as IT modules do not read @Theme annotations when
maven configures the classpath for multimodule projects -->
<delete dir="target/classes/com/vaadin/devbundle" includeemptydirs="true"></delete>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
3 changes: 2 additions & 1 deletion vaadin-dev-bundle/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
src/main/dev-bundle
frontend/index.html
src/main/bundles
vite.*.ts
3 changes: 3 additions & 0 deletions vaadin-hybrid-dev-bundle/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
frontend/index.html
src/main/bundles
vite.*.ts
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"lumoImports": ["typography", "color", "spacing", "badge", "utility"]
}
1 change: 1 addition & 0 deletions vaadin-hybrid-dev-bundle/frontend/views/__dummy__.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const __dummy__ = "Fake view only used to trigger Hilla usage in frontend build";
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.vaadin.devbundle;

import com.vaadin.flow.component.page.AppShellConfigurator;
import com.vaadin.flow.server.PWA;
import com.vaadin.flow.theme.Theme;

@Theme("vaadin-dev-bundle")
@PWA(name = "vaadin-dev-bundle", shortName = "vaadin-dev-bundle")
public class FakeAppConf implements AppShellConfigurator{

}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package com.vaadin.devbundle;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileVisitResult;
import java.nio.file.FileVisitor;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.concurrent.atomic.AtomicInteger;

import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class BundleTest {

@Test
public void usageStatsIncluded() throws IOException {
String needle = "StatisticsGatherer";
Path bundlerBuildFolder = Paths.get("target", "dev-bundle", "webapp",
"VAADIN", "build");

int foundInFiles = findInFiles(bundlerBuildFolder, needle);
Assertions.assertEquals(1, foundInFiles,
"The key '" + needle + "' should be found in one file");
}
@Test
public void copilotIncluded() throws IOException {
String needle = "copilot-main";
Path bundlerBuildFolder = Paths.get("target", "dev-bundle", "webapp",
"VAADIN", "build");

int foundInFiles = findInFiles(bundlerBuildFolder, needle);
Assertions.assertEquals(1, foundInFiles,
"The key '" + needle + "' should be found in one file");
}
@Test
public void hillaIncluded() throws IOException {
String needle = "@vaadin/hilla-frontend";
int foundInFiles = findInBundleBuildFolder(needle);
Assertions.assertEquals(1, foundInFiles,
"The key '" + needle + "' should be found in one file");
}

private int findInBundleBuildFolder(String needle) throws IOException {
Path bundlerBuildFolder = Paths.get("target", "dev-bundle", "webapp",
"VAADIN", "build");
return findInFiles(bundlerBuildFolder, needle);
}

private int findInFiles(Path path, String needle) throws IOException {
AtomicInteger foundInFiles = new AtomicInteger();
Files.walkFileTree(path, new FileVisitor<Path>() {

@Override
public FileVisitResult preVisitDirectory(Path dir,
BasicFileAttributes attrs) throws IOException {
return FileVisitResult.CONTINUE;
}

@Override
public FileVisitResult visitFile(Path file,
BasicFileAttributes attrs) throws IOException {
String content = FileUtils.readFileToString(file.toFile(),
StandardCharsets.UTF_8);
if (content.contains(needle)) {
foundInFiles.incrementAndGet();
}
return FileVisitResult.CONTINUE;
}

@Override
public FileVisitResult visitFileFailed(Path file, IOException exc)
throws IOException {
return FileVisitResult.CONTINUE;
}

@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc)
throws IOException {
return FileVisitResult.CONTINUE;
}

});
return foundInFiles.get();

}
}
3 changes: 3 additions & 0 deletions vaadin-prod-bundle/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
frontend/index.html
src/main/bundles
vite.*.ts

0 comments on commit 22a5a06

Please sign in to comment.