Skip to content

Commit

Permalink
Synchronize dev-server files jmix-framework#3364
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Fedoseev committed Jun 10, 2024
1 parent 2275917 commit cb57cbc
Show file tree
Hide file tree
Showing 8 changed files with 202 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ abstract class AbstractUpdateImports implements Runnable {
private static final String IMPORT_TEMPLATE = "import '%s';";

private static final Pattern STARTING_DOT_SLASH = Pattern.compile("^\\./+");
private static final Pattern VAADIN_LUMO_GLOBAL_IMPORT = Pattern
.compile(".*@vaadin/vaadin-lumo-styles/.*-global.js.*");
final Options options;

private final UnaryOperator<String> themeToLocalPathConverter;
Expand All @@ -96,6 +98,7 @@ abstract class AbstractUpdateImports implements Runnable {
private ClassFinder classFinder;

private final File generatedFlowImports;
private final File generatedFlowWebComponentImports;
private final File generatedFlowDefinitions;
private File chunkFolder;

Expand All @@ -115,6 +118,9 @@ abstract class AbstractUpdateImports implements Runnable {
generatedFlowDefinitions = new File(
generatedFlowImports.getParentFile(),
FrontendUtils.IMPORTS_D_TS_NAME);
generatedFlowWebComponentImports = FrontendUtils
.getFlowGeneratedWebComponentsImports(
options.getFrontendDirectory());
this.chunkFolder = new File(generatedFlowImports.getParentFile(),
"chunks");

Expand All @@ -128,6 +134,8 @@ public void run() {
Map<ChunkInfo, List<String>> javascript = getMergedJavascript();
Map<File, List<String>> output = process(css, javascript);
writeOutput(output);
writeWebComponentImports(
filterWebComponentImports(output.get(generatedFlowImports)));
getLogger().debug("Imports and chunks update took {} ms.",
TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start));
}
Expand Down Expand Up @@ -187,6 +195,28 @@ protected void writeOutput(Map<File, List<String>> outputFiles) {
}
}

// Visible for test
List<String> filterWebComponentImports(List<String> lines) {
if (lines != null) {
// Exclude Lumo global imports for exported web-component
return lines.stream()
.filter(VAADIN_LUMO_GLOBAL_IMPORT.asPredicate().negate())
.collect(Collectors.toList());
}
return lines;
}

private void writeWebComponentImports(List<String> lines) {
if (lines != null) {
try {
FileIOUtils.writeIfChanged(generatedFlowWebComponentImports,
lines);
} catch (IOException e) {
throw new IllegalStateException(
"Failed to update the generated Flow imports", e);
}
}
}
/**
* Processes what the scanner found and produces a set of files to write to
* the generated folder.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class FrontendTools {
* the installed version is older than {@link #SUPPORTED_NODE_VERSION}, i.e.
* {@value #SUPPORTED_NODE_MAJOR_VERSION}.{@value #SUPPORTED_NODE_MINOR_VERSION}.
*/
public static final String DEFAULT_NODE_VERSION = "v20.10.0";
public static final String DEFAULT_NODE_VERSION = "v20.11.1";
/**
* This is the version shipped with the default Node version.
*/
Expand Down Expand Up @@ -117,7 +117,7 @@ public class FrontendTools {
7, 0);

private static final int SUPPORTED_NODE_MAJOR_VERSION = 18;
private static final int SUPPORTED_NODE_MINOR_VERSION = 0;
private static final int SUPPORTED_NODE_MINOR_VERSION = 12;
private static final int SUPPORTED_NPM_MAJOR_VERSION = 8;
private static final int SUPPORTED_NPM_MINOR_VERSION = 6;

Expand All @@ -137,7 +137,7 @@ public class FrontendTools {
static final String SYSTEM_HTTPS_PROXY_PROPERTY_KEY = "HTTPS_PROXY";
static final String SYSTEM_HTTP_PROXY_PROPERTY_KEY = "HTTP_PROXY";

private static final int SUPPORTED_PNPM_MAJOR_VERSION = 5;
private static final int SUPPORTED_PNPM_MAJOR_VERSION = 7;
private static final int SUPPORTED_PNPM_MINOR_VERSION = 0;

private static final FrontendVersion SUPPORTED_PNPM_VERSION = new FrontendVersion(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ public class FrontendUtils {
* file.
*/
public static final String IMPORTS_D_TS_NAME = "generated-flow-imports.d.ts";
public static final String IMPORTS_WEB_COMPONENT_NAME = "generated-flow-webcomponent-imports.js";

public static final String THEME_IMPORTS_D_TS_NAME = "theme.d.ts";
public static final String THEME_IMPORTS_NAME = "theme.js";
Expand Down Expand Up @@ -1288,6 +1289,21 @@ public static File getFlowGeneratedWebComponentsFolder(
"web-components");
}

/**
* Gets the location of the generated import file for exported web
* components.
*
* @param frontendFolder
* the project frontend folder
* @return the location of the generated import JS file for exported web
* components
*/
public static File getFlowGeneratedWebComponentsImports(
File frontendFolder) {
return new File(getFlowGeneratedFolder(frontendFolder),
IMPORTS_WEB_COMPONENT_NAME);
}

public static int findFreePort(int rangeStart, int rangeEnd) {
final String host = "localhost";
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"@polymer/polymer": "3.5.1",
"@vaadin/common-frontend": "0.0.19",
"construct-style-sheets-polyfill": "3.1.0",
"lit": "3.1.0"
"lit": "3.1.2"
},
"devDependencies": {
"async": "3.2.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
"license": "Apache-2.0",
"dependencies": {},
"devDependencies": {
"vite": "5.0.6",
"@vitejs/plugin-react": "4.2.0",
"vite": "5.1.7",
"@vitejs/plugin-react": "4.2.1",
"@vitejs/plugin-react-swc": "3.5.0",
"@rollup/plugin-replace": "5.0.4",
"@rollup/pluginutils": "5.0.5",
"rollup-plugin-visualizer": "5.9.2",
"@rollup/plugin-replace": "5.0.5",
"@rollup/pluginutils": "5.1.0",
"rollup-plugin-visualizer": "5.12.0",
"rollup-plugin-brotli": "3.1.0",
"vite-plugin-checker": "0.6.2",
"vite-plugin-checker": "0.6.4",
"workbox-build": "7.0.0",
"transform-ast": "2.4.4"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2023 Vaadin Ltd.
* Copyright 2000-2024 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
Expand Down Expand Up @@ -118,7 +118,9 @@ function writeThemeFiles(themeFolder, themeName, themeProperties, options) {
imports.push(`import { ${lumoImport} } from '@vaadin/vaadin-lumo-styles/${lumoImport}.js';\n`);
if (lumoImport === 'utility' || lumoImport === 'badge' || lumoImport === 'typography' || lumoImport === 'color') {
// Inject into main document the same way as other Lumo styles are injected
imports.push(`import '@vaadin/vaadin-lumo-styles/${lumoImport}-global.js';\n`);
// Lumo imports go to the theme global imports file to prevent style leaks
// when the theme is applied to an embedded component
globalFileContent.push(`import '@vaadin/vaadin-lumo-styles/${lumoImport}-global.js';\n`);
}
});

Expand Down
Loading

0 comments on commit cb57cbc

Please sign in to comment.