Skip to content

Commit

Permalink
add notes later
Browse files Browse the repository at this point in the history
  • Loading branch information
treblereel committed Jan 25, 2024
1 parent 62aac38 commit 6785e99
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 13 deletions.
2 changes: 1 addition & 1 deletion j2cl-tasks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,4 @@
<scope>test</scope>
</dependency>
</dependencies>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,6 @@ 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);
}

try {
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String scriptsArray = gson.toJson(sourceOrder.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public Task resolve(Project project, Config config) {
depInfoMap = deps.stream()
.map(info -> new DependencyInfoAndSource(
info,
fileNameKey,
() -> Files.readString(lastOutput.resolve(Closure.SOURCES_DIRECTORY_NAME).resolve(info.getName())))
)
.collect(Collectors.toMap(DependencyInfo::getName, Function.identity()));
Expand All @@ -151,7 +152,7 @@ public Task resolve(Project project, Config config) {
input.setCompiler(jsCompiler);
depInfoMap.put(
change.getSourcePath().toString(),
new DependencyInfoAndSource(input, input::getCode)
new DependencyInfoAndSource(input, fileNameKey, input::getCode)
);
}
}
Expand All @@ -170,8 +171,7 @@ public Task resolve(Project project, Config config) {
.withOriginalPath(path.getSourcePath().toString())
.build());
input.setCompiler(jsCompiler);

dependencyInfos.add(new DependencyInfoAndSource(input, input::getCode));
dependencyInfos.add(new DependencyInfoAndSource(input, fileNameKey, input::getCode));
}
}
}
Expand Down Expand Up @@ -202,6 +202,7 @@ public Task resolve(Project project, Config config) {
for (DependencyInfoAndSource info : sorter.getSortedList()) {
String code = info.getSource();
String name = info.getName();
String projectName = info.getProject();

//TODO do we actually need this?
if (Compiler.isFillFileName(name) && code.isEmpty()) {
Expand All @@ -210,7 +211,7 @@ public Task resolve(Project project, Config config) {

// append this file and a comment where it came from
bundleOut.append("//").append(name).append("\n");
bundler.withPath(name).withSourceUrl(Closure.SOURCES_DIRECTORY_NAME + "/" + name).appendTo(bundleOut, info, code);
bundler.withPath(name).withSourceUrl(Closure.SOURCES_DIRECTORY_NAME + "/" + projectName + "/" + name).appendTo(bundleOut, info, code);
bundleOut.append("\n");

}
Expand Down Expand Up @@ -245,8 +246,11 @@ public static class DependencyInfoAndSource implements DependencyInfo {
private final DependencyInfo delegate;
private final SourceSupplier sourceSupplier;

public DependencyInfoAndSource(DependencyInfo delegate, SourceSupplier sourceSupplier) {
private final String project;

public DependencyInfoAndSource(DependencyInfo delegate, String project, SourceSupplier sourceSupplier) {
this.delegate = delegate;
this.project = project.replaceAll("\\.", "-");
this.sourceSupplier = sourceSupplier;
}

Expand Down Expand Up @@ -309,6 +313,10 @@ public boolean getHasExternsAnnotation() {
public boolean getHasNoCompileAnnotation() {
return delegate.getHasNoCompileAnnotation();
}

public String getProject() {
return project;
}
}

public static class DependencyInfoFormat implements DependencyInfo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -51,6 +56,11 @@ public Task resolve(Project project, Config config) {

File bootstrapClasspath = config.getBootstrapClasspath();
List<File> extraClasspath = config.getExtraClasspath();

//*******
boolean sourcemapsEnabled = config.getSourcemapsEnabled();
Path sourceMapsFolder = sourcemapsEnabled ? prepareSourcesFolder(config, project) : null;

return context -> {
if (ownJavaSources.getFilesAndHashes().isEmpty()) {
return;// nothing to do
Expand Down Expand Up @@ -82,6 +92,28 @@ public Task resolve(Project project, Config config) {
if (!j2cl.transpile(javaSources, nativeSources)) {
throw new IllegalStateException("Error while running J2CL");
}

if(sourcemapsEnabled) {
if(sourceMapsFolder.toFile().exists()) {
FileUtils.deleteDirectory(sourceMapsFolder.toFile());
}
sourceMapsFolder.toFile().mkdirs();
FileUtils.copyDirectory(context.outputPath().toFile(), sourceMapsFolder.toFile());
}
};
}

private Path prepareSourcesFolder(Config config, Project project) {
try {
Path initialScriptFile = config.getWebappDirectory().resolve(config.getInitialScriptFilename());
Path outputDir = initialScriptFile.getParent();
Files.createDirectories(outputDir);
Path destSourcesDir = outputDir.resolve(Closure.SOURCES_DIRECTORY_NAME);
Files.createDirectories(destSourcesDir);
Path dist = destSourcesDir.resolve(project.getKey().replaceAll("\\.","-").replaceAll(":","-"));
return dist;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

0 comments on commit 6785e99

Please sign in to comment.