File tree Expand file tree Collapse file tree
main/java/com/vaadin/flow/server/frontend
test/java/com/vaadin/flow/server/frontend Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -283,13 +283,28 @@ private void addWebpackPlugins(JsonObject packageJson) {
283283 packageJson .put (DEV_DEPENDENCIES , devDependencies );
284284 }
285285
286+ String atVaadinPrefix = "@vaadin/" ;
287+ String pluginTargetPrefix = "./"
288+ + (npmFolder .toPath ().relativize (targetFolder ) + "/" )
289+ .replace ('\\' , '/' );
286290 plugins .stream ().filter (plugin -> targetFolder .toFile ().exists ())
287291 .forEach (plugin -> {
288- String pluginTarget = "./" + (npmFolder .toPath ()
289- .relativize (targetFolder ).toString () + "/" + plugin )
290- .replace ('\\' , '/' );
291- devDependencies .put ("@vaadin/" + plugin , pluginTarget );
292+ String pluginTarget = pluginTargetPrefix + plugin ;
293+ devDependencies .put (atVaadinPrefix + plugin , pluginTarget );
292294 });
295+
296+ // Remove plugins previously installed but no longer needed
297+ for (String depKey : devDependencies .keys ()) {
298+ String depVersion = devDependencies .getString (depKey );
299+ if (depKey .startsWith (atVaadinPrefix )
300+ && depVersion .startsWith (pluginTargetPrefix )) {
301+ final String pluginName = depKey
302+ .substring (atVaadinPrefix .length ());
303+ if (!plugins .contains (pluginName )) {
304+ devDependencies .remove (depKey );
305+ }
306+ }
307+ }
293308 }
294309
295310 JsonObject getResourcesPackageJson () throws IOException {
Original file line number Diff line number Diff line change 1616package com .vaadin .flow .server .frontend ;
1717
1818import java .io .File ;
19+ import java .io .FileWriter ;
1920import java .io .IOException ;
2021import java .net .URL ;
2122import java .util .Set ;
@@ -231,6 +232,22 @@ public void getJsonFileContent_incorrectPackageJsonContent_throwsExceptionWithFi
231232 StringContains .containsString ("broken-package.json" ));
232233 }
233234
235+ @ Test
236+ public void removedDisusedPlugins () throws IOException {
237+ File packageJson = new File (npmFolder , "package.json" );
238+ FileWriter packageJsonWriter = new FileWriter (packageJson );
239+ packageJsonWriter .write ("{\" devDependencies\" : {"
240+ + "\" @vaadin/some-old-plugin\" : \" ./target/plugins/some-old-plugin\" ,"
241+ + "\" @vaadin/application-theme-plugin\" : \" ./target/plugins/application-theme-plugin\" }"
242+ + "}" );
243+ packageJsonWriter .close ();
244+ JsonObject actualDevDeps = nodeUpdater .getPackageJson ()
245+ .getObject (NodeUpdater .DEV_DEPENDENCIES );
246+ Assert .assertFalse (actualDevDeps .hasKey ("some-old-plugin" ));
247+ Assert .assertTrue (
248+ actualDevDeps .hasKey ("@vaadin/application-theme-plugin" ));
249+ }
250+
234251 private String getPolymerVersion (JsonObject object ) {
235252 JsonObject deps = object .get ("dependencies" );
236253 String version = deps .getString ("@polymer/polymer" );
You can’t perform that action at this time.
0 commit comments