Skip to content

Commit

Permalink
Adds support for zip inputs as src. (#297)
Browse files Browse the repository at this point in the history
JsCompiler already supports zip input for a while and we are planning to use these rules for J2CL opensource.
  • Loading branch information
gkdn authored Nov 2, 2018
1 parent f9687e2 commit d9d2034
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions closure/compiler/closure_js_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ def _impl(ctx):
# We shall now pass all transitive sources, including externs files.
for src in js.srcs:
inputs.append(src)
if src.path.endswith(".zip"):
all_args.append("--jszip")
all_args.add_all(
[src],
map_each = get_jsfile_path,
Expand Down
4 changes: 2 additions & 2 deletions closure/private/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ def sort_roots(roots):

def convert_path_to_es6_module_name(path, roots):
"""Equivalent to JsCheckerHelper#convertPathToModuleName."""
if not path.endswith(".js"):
fail("Path didn't end with .js: %s" % path)
if not path.endswith(".js") and not path.endswith(".zip"):
fail("Path didn't end with .js or .zip: %s" % path)
module = path[:-3]
for root in roots:
if module.startswith(root + "/"):
Expand Down
9 changes: 7 additions & 2 deletions java/com/google/javascript/jscomp/JsChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,15 @@ public CheckLevel level(JSError error) {
return errorManager.getErrorCount() == 0;
}

private static ImmutableList<SourceFile> getSourceFiles(Iterable<String> filenames) {
private static ImmutableList<SourceFile> getSourceFiles(Iterable<String> filenames)
throws IOException {
ImmutableList.Builder<SourceFile> result = new ImmutableList.Builder<>();
for (String filename : filenames) {
result.add(SourceFile.fromFile(filename));
if (filename.endsWith(".zip")) {
result.addAll(SourceFile.fromZipFile(filename, UTF_8));
} else {
result.add(SourceFile.fromFile(filename));
}
}
return result.build();
}
Expand Down

0 comments on commit d9d2034

Please sign in to comment.