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

Log install/bundling durations #76

Merged
merged 1 commit into from
Aug 28, 2023
Merged
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 @@ -15,6 +15,7 @@
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.nio.file.StandardOpenOption;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -124,14 +125,13 @@ void bundle(WebBundlerConfig config,
&& Files.isDirectory(bundlesBuildContext.bundleDistDir())) {
LOGGER.debug("Bundling not needed for live reload");
handleBundleDistDir(config, generatedBundleProducer, staticResourceProducer, bundlesBuildContext.bundleDistDir(),
false);
null, false);
return;
}
boolean hasScssChange = isLiveReload
&& liveReload.getChangedResources().stream().anyMatch(WebBundlerProcessor::isSassFile);
final Bundler.BundleType type = Bundler.BundleType.valueOf(webDependencies.getType().toString());
final Path targetDir = outputTarget.getOutputDirectory().resolve(TARGET_DIR_NAME);

try {
if (!isLiveReload) {
FileUtil.deleteDirectory(targetDir);
Expand Down Expand Up @@ -201,6 +201,24 @@ void bundle(WebBundlerConfig config,
}
}
if (addedEntryPoints > 0) {

if (!isLiveReload
|| !Objects.equals(webDependencies.getDependencies(), bundlesBuildContext.webDependencies())) {
long startedInstall = Instant.now().toEpochMilli();
Bundler.install(targetDir, webDependencies.getDependencies(), type);
final long duration = Instant.now().minusMillis(startedInstall).toEpochMilli();
if (LOGGER.isDebugEnabled()) {
String deps = webDependencies.getDependencies().stream().map(Path::getFileName).map(Path::toString)
.collect(
Collectors.joining(", "));
LOGGER.infof("%d %s Web dependencies installed in %sms: %s", webDependencies.getDependencies().size(),
webDependencies.getType(), duration, deps);
} else {
LOGGER.infof("%d %s Web Dependencies installed in %sms ", webDependencies.getDependencies().size(),
webDependencies.getType(), duration);
}
}
final long startedBundling = Instant.now().toEpochMilli();
// SCSS conversion
if (!isLiveReload || hasScssChange) {
try (Stream<Path> stream = Files.find(targetDir, Integer.MAX_VALUE,
Expand All @@ -209,26 +227,13 @@ && isCompiledSassFile(p.getFileName().toString()))) {
stream.forEach(p -> convertToScss(p, targetDir));
}
}
if (isLiveReload
&& !Objects.equals(webDependencies.getDependencies(), bundlesBuildContext.webDependencies())) {
Bundler.install(targetDir, webDependencies.getDependencies(), type);
String deps = webDependencies.getDependencies().stream().map(Path::getFileName).map(Path::toString).collect(
Collectors.joining(", "));
LOGGER.infof("%s Web dependencies changed: %s", webDependencies.getType(), deps);
} else {
if (!isLiveReload) {
String deps = webDependencies.getDependencies().stream().map(Path::getFileName).map(Path::toString)
.collect(
Collectors.joining(", "));
LOGGER.infof("%s Web dependencies detected: %s", webDependencies.getType(), deps);
}
}
final BundleResult result = Bundler.bundle(options.build());
if (!result.result().output().isBlank()) {
LOGGER.debugf(result.result().output());
}

handleBundleDistDir(config, generatedBundleProducer, staticResourceProducer, result.dist(), true);
handleBundleDistDir(config, generatedBundleProducer, staticResourceProducer, result.dist(), startedBundling,
true);
liveReload.setContextObject(BundlesBuildContext.class,
new BundlesBuildContext(webDependencies.getDependencies(), entryPoints, result.dist()));
} else {
Expand Down Expand Up @@ -276,7 +281,8 @@ static void convertToScss(Path file, Path root) {
}

void handleBundleDistDir(WebBundlerConfig config, BuildProducer<GeneratedBundleBuildItem> generatedBundleProducer,
BuildProducer<GeneratedStaticResourceBuildItem> staticResourceProducer, Path bundleDir, boolean changed) {
BuildProducer<GeneratedStaticResourceBuildItem> staticResourceProducer, Path bundleDir, Long started,
boolean changed) {
try {
Map<String, String> bundle = new HashMap<>();
final String bundlePublicPath = surroundWithSlashes(config.bundleDir());
Expand All @@ -297,13 +303,19 @@ void handleBundleDistDir(WebBundlerConfig config, BuildProducer<GeneratedBundleB
makePublic(staticResourceProducer, publicPath, path.normalize(), WatchMode.DISABLED, changed);
});
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debugf("Bundle generated in %s (%d files):\n - %s", bundleDir, names.size(),
String.join("\n - ", names));
} else {
LOGGER.infof("Bundle generated in %s (%d files)", bundleDir, names.size());
if (started != null) {
LOGGER.infof("Bundle generated %d files in %sms", names.size(),
Instant.now().minusMillis(started).toEpochMilli());
if (LOGGER.isDebugEnabled()) {
LOGGER.debugf("Bundle dir: '%s'\n - %s", bundleDir, names.size(),
String.join("\n - ", names));
}
if (LOGGER.isDebugEnabled() || LaunchMode.current() == LaunchMode.DEVELOPMENT) {
LOGGER.infof("Bundle#mapping:\n%s", mappingString);
}

}
LOGGER.infof("Bundle#mapping:\n%s", mappingString);

generatedBundleProducer.produce(new GeneratedBundleBuildItem(bundleDir, bundle));
} catch (IOException e) {
throw new RuntimeException(e);
Expand Down