Skip to content

Commit

Permalink
Update J2CL and Closure dependencies (Vertispan#207)
Browse files Browse the repository at this point in the history
This branch brings us up to Nov 2022 for closure-compiler, Aug 2022 for
J2CL, but leaves our current closure-library dependency at Aug 2021 for
now.

The closure-compiler fork includes changes for BUNDLE to avoid parsing
JS files, but only scan for dependencies or ES6 modules that require
transpilation in order to be bundled.

Updating closure-compiler adds a hard dependency on Java 11+, but we've
already officially dropped support for Java 8 in this repository.
  • Loading branch information
niloc132 authored Nov 7, 2022
1 parent 603dacc commit b4159cd
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.auto.service.AutoService;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.javascript.jscomp.deps.ClosureBundler;
import com.vertispan.j2cl.build.task.*;
import com.vertispan.j2cl.tools.Closure;
import org.apache.commons.io.FileUtils;
Expand Down Expand Up @@ -145,11 +146,17 @@ public void finish(TaskContext taskContext) throws IOException {
" elt.async = false;\n" +
" document.head.appendChild(elt);\n" +
"});" + "})();";

// Closure bundler runtime
StringBuilder runtime = new StringBuilder();
new ClosureBundler().appendRuntimeTo(runtime);

Files.write(initialScriptFile.toPath(), Arrays.asList(
defineLine,
intro,
scriptsArray,
outro
outro,
runtime
));
} catch (IOException e) {
throw new UncheckedIOException("Failed to write html import file", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ public boolean compile(
jscompArgs.add("IIFE");
}

if (compilationLevel == CompilationLevel.BUNDLE) {
// avoid injecting libraries, the runtime will be added as part of the BundleJarTask step in the
// initial download
jscompArgs.add("--inject_libraries");
jscompArgs.add("false");
}

for (String entrypoint : entrypoints) {
jscompArgs.add("--entry_point");
jscompArgs.add(entrypoint);
Expand Down
4 changes: 4 additions & 0 deletions j2cl-tasks/src/main/java/com/vertispan/j2cl/tools/J2cl.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.vertispan.j2cl.tools;

import com.google.common.collect.ImmutableList;
import com.google.j2cl.common.OutputUtils;
import com.google.j2cl.common.SourceUtils;
import com.google.j2cl.common.Problems;
Expand All @@ -11,6 +12,7 @@

import javax.annotation.Nonnull;
import java.io.File;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand Down Expand Up @@ -44,6 +46,8 @@ public boolean transpile(List<SourceUtils.FileInfo> sourcesToCompile, List<Sourc
.setOutput(output)
.setSources(sourcesToCompile)
.setNativeSources(nativeSources)
.setKotlinCommonSources(Collections.emptyList())
.setKotlincOptions(ImmutableList.of())
.build();

log.debug(options.toString());
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@
<maven.gpg.plugin.version>1.6</maven.gpg.plugin.version>

<!-- Builder dependencies versions -->
<j2cl.version>0.10.0-3c97afeac</j2cl.version>
<closure.compiler.unshaded.version>v20220502-1</closure.compiler.unshaded.version>
<j2cl.version>0.11.0-9336533b6</j2cl.version>
<closure.compiler.unshaded.version>v20221102-1</closure.compiler.unshaded.version>
<commons.codec.version>1.11</commons.codec.version>
<commons.io.version>2.7</commons.io.version>

Expand Down

0 comments on commit b4159cd

Please sign in to comment.