-
Notifications
You must be signed in to change notification settings - Fork 27
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
Added ability in watch mode to copy source maps to output folder for … #250
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -246,6 +246,12 @@ public class TestMojo extends AbstractBuildMojo { | |||||
@Parameter(defaultValue = "false") | ||||||
protected boolean enableSourcemaps; | ||||||
|
||||||
/** | ||||||
* True to copy only changed source files to the output directory. This is a performance optimization. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
*/ | ||||||
@Parameter(defaultValue = "false") | ||||||
protected boolean enableIncrementalSourcemaps; | ||||||
|
||||||
/** | ||||||
* Closure flag: "Source of translated messages. Currently only supports XTB." | ||||||
*/ | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -129,6 +129,12 @@ public class WatchMojo extends AbstractBuildMojo { | |||||
@Parameter(defaultValue = "true") | ||||||
protected boolean enableSourcemaps; | ||||||
|
||||||
/** | ||||||
* True to copy only changed source files to the output directory. This is a performance optimization. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
*/ | ||||||
@Parameter(defaultValue = "false") | ||||||
protected boolean enableIncrementalSourcemaps; | ||||||
|
||||||
/** | ||||||
* @deprecated Will be removed in 0.21 | ||||||
*/ | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,4 +95,4 @@ | |
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> | ||
</project> |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -74,6 +74,8 @@ public Task resolve(Project project, Config config) { | |||||
} | ||||||
|
||||||
File initialScriptFile = config.getWebappDirectory().resolve(config.getInitialScriptFilename()).toFile(); | ||||||
boolean sourcemapsEnabled = config.getSourcemapsEnabled() && !config.getEnableIncrementalSourcemaps(); | ||||||
|
||||||
Map<String, Object> defines = new LinkedHashMap<>(config.getDefines()); | ||||||
|
||||||
List<Input> outputToCopy = Stream.concat( | ||||||
|
@@ -113,11 +115,14 @@ public void finish(TaskContext taskContext) throws IOException { | |||||
Files.copy(bundle.getAbsolutePath(), targetFile, StandardCopyOption.REPLACE_EXISTING); | ||||||
} | ||||||
|
||||||
File destSourcesDir = outputDir.toPath().resolve(Closure.SOURCES_DIRECTORY_NAME).toFile(); | ||||||
destSourcesDir.mkdirs(); | ||||||
for (Path dir : jsSources.stream().map(Input::getParentPaths).flatMap(Collection::stream).map(p -> p.resolve(Closure | ||||||
.SOURCES_DIRECTORY_NAME)).collect(Collectors.toSet())) { | ||||||
FileUtils.copyDirectory(dir.toFile(), destSourcesDir); | ||||||
// Copy sources to the output directory, if sourcemaps are enabled and incremental source maps is not. | ||||||
if(sourcemapsEnabled) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
File destSourcesDir = outputDir.toPath().resolve(Closure.SOURCES_DIRECTORY_NAME).toFile(); | ||||||
destSourcesDir.mkdirs(); | ||||||
for (Path dir : jsSources.stream().map(Input::getParentPaths).flatMap(Collection::stream).map(p -> p.resolve(Closure | ||||||
.SOURCES_DIRECTORY_NAME)).collect(Collectors.toSet())) { | ||||||
FileUtils.copyDirectory(dir.toFile(), destSourcesDir); | ||||||
} | ||||||
} | ||||||
|
||||||
try { | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,10 +2,15 @@ | |||||
|
||||||
import com.google.auto.service.AutoService; | ||||||
import com.google.j2cl.common.SourceUtils; | ||||||
import com.google.javascript.jscomp.CompilationLevel; | ||||||
import com.vertispan.j2cl.build.task.*; | ||||||
import com.vertispan.j2cl.tools.Closure; | ||||||
import com.vertispan.j2cl.tools.J2cl; | ||||||
import org.apache.commons.io.FileUtils; | ||||||
|
||||||
import java.io.File; | ||||||
import java.io.IOException; | ||||||
import java.nio.file.Files; | ||||||
import java.nio.file.Path; | ||||||
import java.nio.file.PathMatcher; | ||||||
import java.util.Collections; | ||||||
|
@@ -53,6 +58,10 @@ public Task resolve(Project project, Config config) { | |||||
|
||||||
File bootstrapClasspath = config.getBootstrapClasspath(); | ||||||
List<File> extraClasspath = config.getExtraClasspath(); | ||||||
|
||||||
boolean sourcemapsEnabled = config.getSourcemapsEnabled() && config.getEnableIncrementalSourcemaps(); | ||||||
Path sourceMapsFolder = sourcemapsEnabled ? prepareSourcesFolder(config, project) : null; | ||||||
|
||||||
return context -> { | ||||||
if (ownJavaSources.getFilesAndHashes().isEmpty()) { | ||||||
return;// nothing to do | ||||||
|
@@ -84,6 +93,26 @@ public Task resolve(Project project, Config config) { | |||||
if (!j2cl.transpile(javaSources, nativeSources)) { | ||||||
throw new IllegalStateException("Error while running J2CL"); | ||||||
} | ||||||
|
||||||
if(sourcemapsEnabled) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
if(sourceMapsFolder.toFile().exists()) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
FileUtils.deleteDirectory(sourceMapsFolder.toFile()); | ||||||
} | ||||||
sourceMapsFolder.toFile().mkdirs(); | ||||||
FileUtils.copyDirectory(context.outputPath().toFile(), sourceMapsFolder.toFile()); | ||||||
} | ||||||
}; | ||||||
} | ||||||
|
||||||
private Path prepareSourcesFolder(Config config, Project project) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Won't doing this here prevent projects that don't get j2cl run on them (bootstrap, jre, any JS-only dependency) from getting sourcemaps? It seems like this might belong in ClosureBundleTask instead (copy from "here's where my input declared its sourcemaps, skip ahead and copy straight to the output dir). That would also remove the need to have a "is compilationLevel==BUNDLE_JAR", which technically this should have as written - if you have this property on when doing a prod build, you're going to write a bunch of extra stuff to prod that you probably don't want... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Definitely, what's good is that the projects you mentioned are those that won't change during the j2cl:watch process, which means their source maps need to be copied only once. ClosureBundleTask is definitely the best place for this. I was thinking about how to copy the source maps of reactor modules in ClosureBundleTask, rather than in J2clTask, but I couldn't figure out how to let ClosureBundleTask know which projects have changed and which have not. Maybe you have some ideas? |
||||||
try { | ||||||
Path initialScriptFile = config.getWebappDirectory().resolve(config.getInitialScriptFilename()); | ||||||
Path destSourcesDir = Files.createDirectories(initialScriptFile.getParent()).resolve(Closure.SOURCES_DIRECTORY_NAME); | ||||||
return Files.createDirectories(destSourcesDir).resolve(project.getKey() | ||||||
.replaceAll("\\.","-") | ||||||
.replaceAll(":","-")); | ||||||
} catch (IOException e) { | ||||||
throw new RuntimeException(e); | ||||||
} | ||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically you are sacrificing correctness for speed, especially if your "speed" also comes in the form of "i made it faster by using a cache outside of target".