Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix faulty given path for webpackOutput #12122

Merged
merged 2 commits into from
Oct 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
import elemental.json.JsonObject;

import static com.vaadin.flow.server.Constants.PACKAGE_JSON;
import static com.vaadin.flow.server.Constants.VAADIN_SERVLET_RESOURCES;
import static com.vaadin.flow.server.InitParameters.SERVLET_PARAMETER_DEVMODE_OPTIMIZE_BUNDLE;
import static com.vaadin.flow.server.frontend.FrontendUtils.DEFAULT_FRONTEND_DIR;
import static com.vaadin.flow.server.frontend.FrontendUtils.DEFAULT_GENERATED_DIR;
Expand Down Expand Up @@ -287,10 +288,11 @@ public static void initDevModeHandler(Set<Class<?>> classes,

File generatedPackages = new File(builder.generatedFolder,
PACKAGE_JSON);

File target = new File(baseDir, "target");
// Always update to auto-generated webpack configuration
builder.withWebpack(builder.npmFolder, FrontendUtils.WEBPACK_CONFIG,
FrontendUtils.WEBPACK_GENERATED);
builder.withWebpack(
new File(target, "classes/" + VAADIN_SERVLET_RESOURCES),
FrontendUtils.WEBPACK_CONFIG, FrontendUtils.WEBPACK_GENERATED);

// If we are missing either the base or generated package json files
// generate those
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import java.util.List;
import java.util.Set;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import net.jcip.annotations.NotThreadSafe;

Expand Down Expand Up @@ -245,6 +247,33 @@ public void should_Always_Update_Generated_Webpack_Conf() throws Exception {
}
}

@Test
public void generated_output_should_be_in_target_classes()
mshabarov marked this conversation as resolved.
Show resolved Hide resolved
throws Exception {
File generatedWebpackFile = new File(webpackFile.getParentFile(),
FrontendUtils.WEBPACK_GENERATED);
try (FileWriter writer = new FileWriter(generatedWebpackFile)) {
process();

final String generated = IOUtils.toString(
generatedWebpackFile.toURI(), StandardCharsets.UTF_8);

final Pattern compile = Pattern.compile(
"projectStaticAssetsOutputFolder.* '(.*)'");
final Matcher matcher = compile.matcher(generated);
matcher.find();

Assert.assertTrue(
"Generated webpack configuration contained faulty path ´"
+ matcher.group(1)
+ "' instead of 'target/classes/META-INF/VAADIN/static'",
generated.contains(
"const projectStaticAssetsOutputFolder = require('path').resolve(__dirname, 'target/classes/META-INF/VAADIN/static');"));
} finally {
generatedWebpackFile.delete();
}
}

@Test
public void should_Run_Updaters_doesNotThrow() throws Exception {
// no any exception means that updaters are executed and dev mode server
Expand Down