4343import java .util .stream .Collectors ;
4444import java .util .stream .Stream ;
4545
46- import org .slf4j .Logger ;
47-
4846import com .vaadin .flow .internal .StringUtil ;
4947import com .vaadin .flow .internal .UrlUtil ;
5048import com .vaadin .flow .server .Constants ;
5553import com .vaadin .flow .server .frontend .scanner .FrontendDependenciesScanner ;
5654import com .vaadin .flow .shared .ApplicationConstants ;
5755import com .vaadin .flow .theme .AbstractTheme ;
56+ import org .slf4j .Logger ;
5857
5958import static com .vaadin .flow .server .Constants .COMPATIBILITY_RESOURCES_FRONTEND_DEFAULT ;
6059import static com .vaadin .flow .server .Constants .PACKAGE_JSON ;
@@ -96,6 +95,8 @@ abstract class AbstractUpdateImports implements Runnable {
9695 + " return !ae || ae.blur() || ae.focus() || true;\n " + "}" ;
9796 private static final String IMPORT_TEMPLATE = "import '%s';" ;
9897 private static final Pattern STARTING_DOT_SLASH = Pattern .compile ("^\\ ./+" );
98+ private static final Pattern VAADIN_LUMO_GLOBAL_IMPORT = Pattern
99+ .compile (".*@vaadin/vaadin-lumo-styles/.*-global.js.*" );
99100 final Options options ;
100101
101102 private final UnaryOperator <String > themeToLocalPathConverter ;
@@ -106,7 +107,8 @@ abstract class AbstractUpdateImports implements Runnable {
106107
107108 private ClassFinder classFinder ;
108109
109- private final File generatedFlowImports ;
110+ final File generatedFlowImports ;
111+ final File generatedFlowWebComponentImports ;
110112 private final File generatedFlowDefinitions ;
111113 private File chunkFolder ;
112114
@@ -123,6 +125,11 @@ abstract class AbstractUpdateImports implements Runnable {
123125 generatedFlowDefinitions = new File (
124126 generatedFlowImports .getParentFile (),
125127 FrontendUtils .IMPORTS_D_TS_NAME );
128+
129+ generatedFlowWebComponentImports = new File (
130+ FrontendUtils .getFlowGeneratedWebComponentsFolder (
131+ options .getFrontendDirectory ()),
132+ FrontendUtils .IMPORTS_WEB_COMPONENT_NAME );
126133 this .chunkFolder = new File (generatedFlowImports .getParentFile (),
127134 "chunks" );
128135
@@ -138,6 +145,8 @@ public void run() {
138145
139146 Map <File , List <String >> output = process (css , javascript );
140147 writeOutput (output );
148+ writeWebComponentImports (
149+ filterWebComponentImports (output .get (generatedFlowImports )));
141150
142151 getLogger ().debug ("Imports and chunks update took {} ms." ,
143152 TimeUnit .NANOSECONDS .toMillis (System .nanoTime () - start ));
@@ -198,6 +207,29 @@ protected void writeOutput(Map<File, List<String>> outputFiles) {
198207 }
199208 }
200209
210+ // Visible for test
211+ List <String > filterWebComponentImports (List <String > lines ) {
212+ if (lines != null ) {
213+ // Exclude Lumo global imports for exported web-component
214+ return lines .stream ()
215+ .filter (VAADIN_LUMO_GLOBAL_IMPORT .asPredicate ().negate ())
216+ .collect (Collectors .toList ());
217+ }
218+ return lines ;
219+ }
220+
221+ private void writeWebComponentImports (List <String > lines ) {
222+ if (lines != null ) {
223+ try {
224+ FileIOUtils .writeIfChanged (generatedFlowWebComponentImports ,
225+ lines );
226+ } catch (IOException e ) {
227+ throw new IllegalStateException (
228+ "Failed to update the generated Flow imports" , e );
229+ }
230+ }
231+ }
232+
201233 /**
202234 * Processes what the scanner found and produces a set of files to write to
203235 * the generated folder.
0 commit comments