Skip to content

Commit dda1953

Browse files
vaadin-botArtur-
andauthored
fix: Make linking to packages in the file system work (#12424) (#12517)
Fixes vaadin/hilla#126 Co-authored-by: Artur <artur@vaadin.com>
1 parent ba1db11 commit dda1953

9 files changed

Lines changed: 148 additions & 13 deletions

File tree

‎flow-server/src/main/java/com/vaadin/flow/server/frontend/NodeUpdater.java‎

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -502,19 +502,27 @@ private int handleExistingVaadinDep(JsonObject json, String pkg,
502502
boolean added = false;
503503
FrontendVersion vaadinVersion = toVersion(vaadinDeps, pkg);
504504
if (json.hasKey(pkg)) {
505-
FrontendVersion packageVersion = toVersion(json, pkg);
506-
FrontendVersion newVersion = new FrontendVersion(version);
507-
// Vaadin and package.json versions are the same, but dependency
508-
// updates (can be up or down)
509-
if (vaadinVersion.isEqualTo(packageVersion)
510-
&& !vaadinVersion.isEqualTo(newVersion)) {
511-
json.put(pkg, version);
512-
added = true;
513-
// if vaadin and package not the same, but new version is newer
514-
// update package version.
515-
} else if (newVersion.isNewerThan(packageVersion)) {
516-
json.put(pkg, version);
517-
added = true;
505+
try {
506+
FrontendVersion packageVersion = toVersion(json, pkg);
507+
FrontendVersion newVersion = new FrontendVersion(version);
508+
// Vaadin and package.json versions are the same, but dependency
509+
// updates (can be up or down)
510+
if (vaadinVersion.isEqualTo(packageVersion)
511+
&& !vaadinVersion.isEqualTo(newVersion)) {
512+
json.put(pkg, version);
513+
added = true;
514+
// if vaadin and package not the same, but new version is
515+
// newer
516+
// update package version.
517+
} else if (newVersion.isNewerThan(packageVersion)) {
518+
json.put(pkg, version);
519+
added = true;
520+
}
521+
} catch (NumberFormatException e) { // NOSONAR
522+
/*
523+
* If the current version is not parseable, it can refer to a
524+
* file and we should leave it alone
525+
*/
518526
}
519527
} else {
520528
json.put(pkg, version);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
window.packageOutsideNpm = () => {
2+
return "It works";
3+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "package-outside-npm",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "",
10+
"license": "Apache-2.0"
11+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"name": "no-name",
3+
"license": "UNLICENSED",
4+
"dependencies": {
5+
"@polymer/polymer": "3.2.0",
6+
"@vaadin/common-frontend": "0.0.17",
7+
"@vaadin/flow-frontend": "./target/flow-frontend",
8+
"@vaadin/router": "1.7.4",
9+
"@vaadin/vaadin-lumo-styles": "22.0.0-alpha9",
10+
"construct-style-sheets-polyfill": "3.0.4",
11+
"copy-to-clipboard": "^3.3.1",
12+
"lit": "2.0.0",
13+
"package-outside-npm": "link:package-outside-npm",
14+
"package2-outside-npm": "./package2-outside-npm"
15+
},
16+
"devDependencies": {
17+
"@vaadin/application-theme-plugin": "./target/plugins/application-theme-plugin",
18+
"@vaadin/build-status-plugin": "./target/plugins/build-status-plugin",
19+
"@vaadin/theme-live-reload-plugin": "./target/plugins/theme-live-reload-plugin",
20+
"@vaadin/theme-loader": "./target/plugins/theme-loader",
21+
"glob": "7.1.6",
22+
"mkdirp": "1.0.4",
23+
"rollup-plugin-brotli": "3.1.0",
24+
"typescript": "4.4.3",
25+
"vite": "v2.7.0-beta.7",
26+
"vite-plugin-checker": "0.3.4",
27+
"workbox-core": "6.2.0",
28+
"workbox-precaching": "6.2.0"
29+
},
30+
"vaadin": {
31+
"dependencies": {
32+
"@polymer/polymer": "3.2.0",
33+
"@vaadin/common-frontend": "0.0.17",
34+
"@vaadin/router": "1.7.4",
35+
"@vaadin/vaadin-lumo-styles": "22.0.0-alpha9",
36+
"construct-style-sheets-polyfill": "3.0.4",
37+
"lit": "2.0.0"
38+
},
39+
"devDependencies": {
40+
"glob": "7.1.6",
41+
"mkdirp": "1.0.4",
42+
"rollup-plugin-brotli": "3.1.0",
43+
"typescript": "4.4.3",
44+
"vite": "v2.7.0-beta.7",
45+
"vite-plugin-checker": "0.3.4",
46+
"workbox-core": "6.2.0",
47+
"workbox-precaching": "6.2.0"
48+
},
49+
"hash": "b2e71740a9ce5a3c40d524fd9d3fa7fdda7fb5cff652d7c037e79819818b81b9"
50+
}
51+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
window.package2OutsideNpm = () => {
2+
return "It works";
3+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "package2-outside-npm",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "",
10+
"license": "Apache-2.0"
11+
}

‎flow-tests/test-frontend/vite-basics/src/main/java/com/vaadin/viteapp/views/empty/MainView.java‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@
1212

1313
@Route("")
1414
@JsModule("./jsonloader.js")
15+
@JsModule("package-outside-npm/index.js")
16+
@JsModule("package2-outside-npm/index.js")
1517
public class MainView extends Div {
1618

1719
public static final String LOAD_AND_SHOW_JSON = "loadAndShowJson";
1820
public static final String JSON_CONTAINER = "jsonContainer";
1921
public static final String PLANT = "plant";
22+
public static final String OUTSIDE = "outsideButton";
23+
public static final String OUTSIDE_RESULT = "outsideResult";
2024

2125
public MainView() {
2226
Image img = new Image("themes/vite-basics/images/plant.png",
@@ -54,6 +58,17 @@ public MainView() {
5458
.isEnabled(FeatureFlags.VITE));
5559
viteStatus.setId("status");
5660
add(viteStatus);
61+
62+
NativeButton checkOutsideJs = new NativeButton("Check outside JS",
63+
e -> {
64+
getElement().executeJs(OUTSIDE_RESULT
65+
+ ".innerText = window.packageOutsideNpm() + ' - ' + window.package2OutsideNpm();");
66+
});
67+
checkOutsideJs.setId(OUTSIDE);
68+
add(checkOutsideJs);
69+
Paragraph outsideStatus = new Paragraph();
70+
outsideStatus.setId(OUTSIDE_RESULT);
71+
add(outsideStatus);
5772
}
5873

5974
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.vaadin.viteapp;
2+
3+
import com.vaadin.flow.component.html.NativeButton;
4+
import com.vaadin.flow.component.html.testbench.NativeButtonElement;
5+
import com.vaadin.flow.component.html.testbench.ParagraphElement;
6+
import com.vaadin.viteapp.views.empty.MainView;
7+
8+
import org.junit.Assert;
9+
import org.junit.Test;
10+
11+
public class ExternalPackageIT extends ViteDevModeIT {
12+
13+
@Test
14+
public void packageOutsideNpmWorks() {
15+
$(NativeButtonElement.class).id(MainView.OUTSIDE).click();
16+
Assert.assertEquals("It works - It works", $(ParagraphElement.class)
17+
.id(MainView.OUTSIDE_RESULT).getText());
18+
}
19+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { UserConfigFn } from 'vite';
2+
import { overrideVaadinConfig } from './vite.generated';
3+
4+
const customConfig: UserConfigFn = (env) => ({
5+
// Here you can add custom Vite parameters
6+
// https://vitejs.dev/config/
7+
server: {
8+
fs: {
9+
allow: ['../package-outside-npm', '../package2-outside-npm']
10+
}
11+
}
12+
});
13+
14+
export default overrideVaadinConfig(customConfig);

0 commit comments

Comments
 (0)