Update toolchain

Bazel to 0.14.0
angular/ngcontainer to 0.3.1
rules_nodejs to 0.10.0

Add buildifier formatting for BUILD files
Closes #219

PiperOrigin-RevId: 200431874
diff --git a/.circleci/config.yml b/.circleci/config.yml
index 701c4a1..010e406 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -9,8 +9,8 @@
 
 ## IMPORTANT
 # If you change the `docker_image` version, also change the `cache_key` suffix
-var_1: &docker_image angular/ngcontainer:0.3.0
-var_2: &cache_key rules_typescript-{{ checksum "yarn.lock" }}-0.3.0
+var_1: &docker_image angular/ngcontainer:0.3.1
+var_2: &cache_key rules_typescript-{{ checksum "yarn.lock" }}-0.3.1
 var_3: &setup-bazel-remote-cache
   run:
     name: Start up bazel remote cache proxy
@@ -107,7 +107,19 @@
       - run: .circleci/setup_cache.sh
       - run: sudo cp .circleci/bazel.rc /etc/bazel.bazelrc
       - *setup-bazel-remote-cache
-      - run: yarn skylint
+
+      # Run the skylark linter to check our Bazel rules
+      # deprecated-api is disabled because we legacy providers for typescript
+      # which cannot be upgraded to modern providers without breaking compatability
+      - run: 'find . -type f -name "*.bzl" |
+              xargs java -jar /usr/local/bin/Skylint_deploy.jar --disable-checks=deprecated-api ||
+              (echo -e "\n.bzl files have lint errors. Please run ''yarn skylint''"; exit 1)'
+
+      # Enforce that BUILD files are formatted. Note that this uses the version of buildifier
+      # from the docker image above - take care that you use the same version when you run
+      # buildifier locally on your change.
+      - run: 'buildifier -mode=check $(find . -type f -name BUILD.bazel ) ||
+              (echo "BUILD files not formatted. Please run ''yarn buildifier''" ; exit 1)'
 
 workflows:
   version: 2
@@ -117,4 +129,4 @@
       - build
       - build_no_bazelrc
       - test
-      - lint
\ No newline at end of file
+      - lint
diff --git a/BUILD.bazel b/BUILD.bazel
index 461d901..8da32ff 100644
--- a/BUILD.bazel
+++ b/BUILD.bazel
@@ -34,7 +34,7 @@
     srcs = glob([
         "node_modules/**/*.js",
         "node_modules/**/*.d.ts",
-        "node_modules/**/*.json"
+        "node_modules/**/*.json",
     ] + [
         # Needed because http-server has a bin with no .js extension
         "node_modules/http-server/**",
@@ -47,9 +47,9 @@
 skylark_doc(
     name = "docs",
     srcs = [
-        "//internal:ts_repositories.bzl",
         "//internal:build_defs.bzl",
         "//internal:ts_config.bzl",
+        "//internal:ts_repositories.bzl",
         "//internal/devserver:ts_devserver.bzl",
         "//internal/karma:ts_web_test.bzl",
         "//internal/protobufjs:ts_proto_library.bzl",
diff --git a/WORKSPACE b/WORKSPACE
index 01388e1..66defab 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -15,13 +15,76 @@
 workspace(name = "build_bazel_rules_typescript")
 load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
 
+#
+# Download Bazel toolchain dependencies as needed by build actions
+#
+
 http_archive(
     name = "build_bazel_rules_nodejs",
-    urls = ["https://github.com/bazelbuild/rules_nodejs/archive/0.9.1.zip"],
-    strip_prefix = "rules_nodejs-0.9.1",
-    sha256 = "6139762b62b37c1fd171d7f22aa39566cb7dc2916f0f801d505a9aaf118c117f",
+    urls = ["https://github.com/bazelbuild/rules_nodejs/archive/0.10.0.zip"],
+    strip_prefix = "rules_nodejs-0.10.0",
+    sha256 = "2f77623311da8b5009b1c7eade12de8e15fa3cd2adf9dfcc9f87cb2082b2211f",
 )
 
+http_archive(
+    name = "io_bazel_rules_go",
+    urls = [
+        "http://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/0.10.3/rules_go-0.10.3.tar.gz",
+        "https://github.com/bazelbuild/rules_go/releases/download/0.10.3/rules_go-0.10.3.tar.gz"
+    ],
+    sha256 = "feba3278c13cde8d67e341a837f69a029f698d7a27ddbb2a202be7a10b22142a",
+)
+
+# This commit matches the version of buildifier in angular/ngcontainer
+# If you change this, also check if it matches the version in the angular/ngcontainer
+# version in /.circleci/config.yml
+BAZEL_BUILDTOOLS_VERSION = "82b21607e00913b16fe1c51bec80232d9d6de31c"
+
+http_archive(
+    name = "com_github_bazelbuild_buildtools",
+    urls = ["https://github.com/bazelbuild/buildtools/archive/%s.zip" % BAZEL_BUILDTOOLS_VERSION],
+    strip_prefix = "buildtools-%s" % BAZEL_BUILDTOOLS_VERSION,
+    sha256 = "edb24c2f9c55b10a820ec74db0564415c0cf553fa55e9fc709a6332fb6685eff",
+)
+
+http_archive(
+    name = "io_bazel",
+    urls = ["https://github.com/bazelbuild/bazel/releases/download/0.11.1/bazel-0.11.1-dist.zip"],
+    sha256 = "e8d762bcc01566fa50952c8028e95cfbe7545a39b8ceb3a0d0d6df33b25b333f",
+)
+
+http_archive(
+    name = "bazel_gazelle",
+    urls = ["https://github.com/bazelbuild/bazel-gazelle/releases/download/0.10.1/bazel-gazelle-0.10.1.tar.gz"],
+    sha256 = "d03625db67e9fb0905bbd206fa97e32ae9da894fe234a493e7517fd25faec914",
+)
+
+http_archive(
+    name = "io_bazel_rules_webtesting",
+    urls = ["https://github.com/bazelbuild/rules_webtesting/archive/v0.2.0.zip"],
+    strip_prefix = "rules_webtesting-0.2.0",
+    sha256 = "cecc12f07e95740750a40d38e8b14b76fefa1551bef9332cb432d564d693723c",
+)
+
+http_archive(
+    name = "io_bazel_rules_sass",
+    urls = ["https://github.com/bazelbuild/rules_sass/archive/0.0.3.zip"],
+    strip_prefix = "rules_sass-0.0.3",
+    sha256 = "8fa98e7b48a5837c286a1ea254b5a5c592fced819ee9fe4fdd759768d97be868",
+)
+
+http_archive(
+    name = "io_bazel_skydoc",
+    urls = ["https://github.com/bazelbuild/skydoc/archive/0ef7695c9d70084946a3e99b89ad5a99ede79580.zip"],
+    strip_prefix = "skydoc-0ef7695c9d70084946a3e99b89ad5a99ede79580",
+    sha256 = "491f9e142b870b18a0ec8eb3d66636eeceabe5f0c73025706c86f91a1a2acb4d",
+)
+
+#
+# Load and install our dependencies downloaded above.
+#
+
+
 load("@build_bazel_rules_nodejs//:defs.bzl", "node_repositories", "yarn_install")
 
 # Use a bazel-managed npm dependency, allowing us to test resolution to these paths
@@ -43,48 +106,18 @@
   package_json = ["//:package.json"],
   preserve_symlinks = True)
 
-http_archive(
-    name = "io_bazel_rules_go",
-    urls = [
-        "http://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/0.10.3/rules_go-0.10.3.tar.gz",
-        "https://github.com/bazelbuild/rules_go/releases/download/0.10.3/rules_go-0.10.3.tar.gz"
-    ],
-    sha256 = "feba3278c13cde8d67e341a837f69a029f698d7a27ddbb2a202be7a10b22142a",
-)
-
-http_archive(
-    name = "io_bazel",
-    urls = ["https://github.com/bazelbuild/bazel/releases/download/0.9.0/bazel-0.9.0-dist.zip"],
-    sha256 = "efb28fed4ffcfaee653e0657f6500fc4cbac61e32104f4208da385676e76312a",
-)
-
-http_archive(
-    name = "bazel_gazelle",
-    urls = ["https://github.com/bazelbuild/bazel-gazelle/releases/download/0.10.1/bazel-gazelle-0.10.1.tar.gz"],
-    sha256 = "d03625db67e9fb0905bbd206fa97e32ae9da894fe234a493e7517fd25faec914",
-)
-
 load("@io_bazel_rules_go//go:def.bzl", "go_rules_dependencies", "go_register_toolchains")
 
 go_rules_dependencies()
-
 go_register_toolchains()
 
 load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
 
 gazelle_dependencies()
 
-http_archive(
-    name = "io_bazel_rules_webtesting",
-    urls = ["https://github.com/bazelbuild/rules_webtesting/archive/v0.2.0.zip"],
-    strip_prefix = "rules_webtesting-0.2.0",
-    sha256 = "cecc12f07e95740750a40d38e8b14b76fefa1551bef9332cb432d564d693723c",
-)
-
 load("@io_bazel_rules_webtesting//web:repositories.bzl", "browser_repositories", "web_test_repositories")
 
 web_test_repositories()
-
 browser_repositories(
     chromium = True,
     firefox = True,
@@ -94,23 +127,8 @@
 
 ts_setup_workspace()
 
-#############################################
-# Dependencies for generating documentation #
-#############################################
-
-http_archive(
-    name = "io_bazel_rules_sass",
-    urls = ["https://github.com/bazelbuild/rules_sass/archive/0.0.3.zip"],
-    strip_prefix = "rules_sass-0.0.3",
-    sha256 = "8fa98e7b48a5837c286a1ea254b5a5c592fced819ee9fe4fdd759768d97be868",
-)
 load("@io_bazel_rules_sass//sass:sass.bzl", "sass_repositories")
 sass_repositories()
 
-http_archive(
-    name = "io_bazel_skydoc",
-    urls = ["https://github.com/bazelbuild/skydoc/archive/0ef7695c9d70084946a3e99b89ad5a99ede79580.zip"],
-    strip_prefix = "skydoc-0ef7695c9d70084946a3e99b89ad5a99ede79580",
-)
 load("@io_bazel_skydoc//skylark:skylark.bzl", "skydoc_repositories")
 skydoc_repositories()
diff --git a/examples/BUILD.bazel b/examples/BUILD.bazel
index 3d1bcbc..db5bf95 100644
--- a/examples/BUILD.bazel
+++ b/examples/BUILD.bazel
@@ -24,8 +24,8 @@
 ts_library(
     name = "foo_ts_library",
     srcs = [
-        ":types",
         "foo.ts",
+        ":types",
     ],
     tsconfig = ":tsconfig.json",
     deps = ["//examples/generated_ts"],
@@ -37,7 +37,7 @@
     tsconfig = ":tsconfig.json",
     deps = [
         ":foo_ts_library",
-        "//examples/some_library:lib",
         "//examples/generated_ts",
+        "//examples/some_library:lib",
     ],
 )
diff --git a/examples/app/BUILD.bazel b/examples/app/BUILD.bazel
index 8ec42e1..0d5cc64 100644
--- a/examples/app/BUILD.bazel
+++ b/examples/app/BUILD.bazel
@@ -7,22 +7,22 @@
 
 ts_devserver(
     name = "devserver",
-    # We'll collect all the devmode JS sources from these TypeScript libraries
-    deps = [":app"],
+    port = 8080,
     # This is the path we'll request from the browser, see index.html
     serving_path = "/bundle.min.js",
     # The devserver can serve our static files too
     static_files = ["index.html"],
-    port = 8080,
+    # We'll collect all the devmode JS sources from these TypeScript libraries
+    deps = [":app"],
 )
 
 # Test for production mode
-load("@build_bazel_rules_nodejs//:defs.bzl", "rollup_bundle", "nodejs_binary")
+load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary", "rollup_bundle")
 
 rollup_bundle(
     name = "bundle",
-    deps = [":app"],
     entry_point = "examples/app/app",
+    deps = [":app"],
 )
 
 nodejs_binary(
diff --git a/examples/bazel_managed_deps/BUILD.bazel b/examples/bazel_managed_deps/BUILD.bazel
index d3084b4..536a24e 100644
--- a/examples/bazel_managed_deps/BUILD.bazel
+++ b/examples/bazel_managed_deps/BUILD.bazel
@@ -3,6 +3,6 @@
 ts_library(
     name = "bazel_managed_deps",
     srcs = ["index.ts"],
-    tsconfig = ":tsconfig.json",
     node_modules = "@build_bazel_rules_typescript_internal_bazel_managed_deps//:node_modules",
+    tsconfig = ":tsconfig.json",
 )
diff --git a/examples/generated_ts/BUILD.bazel b/examples/generated_ts/BUILD.bazel
index 380aaad..e488e57 100644
--- a/examples/generated_ts/BUILD.bazel
+++ b/examples/generated_ts/BUILD.bazel
@@ -3,12 +3,12 @@
 package(default_visibility = ["//visibility:public"])
 
 genrule(
-  name = "foo_ts",
-  outs = ["foo.ts"],
-  cmd = "echo 'export const a = 1;' > $@",
+    name = "foo_ts",
+    outs = ["foo.ts"],
+    cmd = "echo 'export const a = 1;' > $@",
 )
 
 ts_library(
-  name = "generated_ts",
-  srcs = [":foo.ts"],
+    name = "generated_ts",
+    srcs = [":foo.ts"],
 )
diff --git a/examples/protocol_buffers/BUILD.bazel b/examples/protocol_buffers/BUILD.bazel
index 9d2aedb..b7dd608 100644
--- a/examples/protocol_buffers/BUILD.bazel
+++ b/examples/protocol_buffers/BUILD.bazel
@@ -1,8 +1,9 @@
-load("@build_bazel_rules_typescript//:defs.bzl",
+load(
+    "@build_bazel_rules_typescript//:defs.bzl",
+    "ts_devserver",
     "ts_library",
     "ts_proto_library",
     "ts_web_test_suite",
-    "ts_devserver",
 )
 
 proto_library(
@@ -33,12 +34,12 @@
 
 ts_web_test_suite(
     name = "test",
-    deps = ["test_lib"],
     bootstrap = ["@build_bazel_rules_typescript//:protobufjs_bootstrap_scripts"],
     browsers = [
-      "@io_bazel_rules_webtesting//browsers:chromium-local",
-      "@io_bazel_rules_webtesting//browsers:firefox-local",
+        "@io_bazel_rules_webtesting//browsers:chromium-local",
+        "@io_bazel_rules_webtesting//browsers:firefox-local",
     ],
+    deps = ["test_lib"],
 )
 
 ts_library(
@@ -49,18 +50,17 @@
 
 ts_devserver(
     name = "devserver",
-    deps = [":app"],
-    entry_module = "build_bazel_rules_typescript/examples/protocol_buffers/app",
     bootstrap = ["@build_bazel_rules_typescript//:protobufjs_bootstrap_scripts"],
+    entry_module = "build_bazel_rules_typescript/examples/protocol_buffers/app",
     port = 8080,
+    deps = [":app"],
 )
 
 # Test for production mode
-load("@build_bazel_rules_nodejs//:defs.bzl", "rollup_bundle", "nodejs_binary")
+load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary", "rollup_bundle")
 
 rollup_bundle(
     name = "bundle",
-    deps = [":app"],
     entry_point = "examples/protocol_buffers/app",
     # TODO(alexeagle): we should be able to get this from //:protobufjs_bootstrap_scripts
     # and automatically plumb it through to Rollup.
@@ -68,6 +68,7 @@
         "long": "Long",
         "protobufjs/minimal": "protobuf",
     },
+    deps = [":app"],
 )
 
 # Needed because the prodserver only loads static files that appear under this
@@ -75,12 +76,12 @@
 genrule(
     name = "protobufjs",
     srcs = [
-      "@build_bazel_rules_typescript_protobufs_compiletime_deps//:node_modules/protobufjs/dist/minimal/protobuf.min.js",
-      "@build_bazel_rules_typescript_protobufs_compiletime_deps//:node_modules/long/dist/long.js",
+        "@build_bazel_rules_typescript_protobufs_compiletime_deps//:node_modules/protobufjs/dist/minimal/protobuf.min.js",
+        "@build_bazel_rules_typescript_protobufs_compiletime_deps//:node_modules/long/dist/long.js",
     ],
     outs = [
-      "protobuf.min.js",
-      "long.js"
+        "protobuf.min.js",
+        "long.js",
     ],
     cmd = "outs=($(OUTS)); d=$$(dirname $${outs[0]}); for s in $(SRCS); do cp $$s $$d; done",
 )
@@ -90,8 +91,8 @@
     args = ["./examples/protocol_buffers"],
     data = [
         "index.html",
-        ":protobufjs",
         ":bundle",
+        ":protobufjs",
     ],
     entry_point = "http-server/bin/http-server",
 )
diff --git a/examples/testing/BUILD.bazel b/examples/testing/BUILD.bazel
index 0dc1758..b719e7c 100644
--- a/examples/testing/BUILD.bazel
+++ b/examples/testing/BUILD.bazel
@@ -7,37 +7,37 @@
 
 ts_library(
     name = "tests",
-    srcs = glob(["*.spec.ts"]),
-    deps = [":lib"],
-    tsconfig = ":tsconfig.json",
     testonly = 1,
+    srcs = glob(["*.spec.ts"]),
+    tsconfig = ":tsconfig.json",
+    deps = [":lib"],
 )
 
 ts_web_test_suite(
     name = "testing",
-    deps = [
-      ":tests",
+    browsers = [
+        "@io_bazel_rules_webtesting//browsers:chromium-local",
+        "@io_bazel_rules_webtesting//browsers:firefox-local",
     ],
     static_files = [
-      "static_script.js",
+        "static_script.js",
     ],
-    browsers = [
-      "@io_bazel_rules_webtesting//browsers:chromium-local",
-      "@io_bazel_rules_webtesting//browsers:firefox-local",
+    deps = [
+        ":tests",
     ],
 )
 
 ts_web_test_suite(
     name = "testing_sauce",
-    deps = [
-      ":tests",
-    ],
     browsers = [
-      "@io_bazel_rules_webtesting//browsers/sauce:chrome-win10",
+        "@io_bazel_rules_webtesting//browsers/sauce:chrome-win10",
     ],
     tags = [
         "sauce",
         # TODO(alexeagle): enable on CI once we have set the SAUCE env variables
         "manual",
     ],
+    deps = [
+        ":tests",
+    ],
 )
diff --git a/internal/BUILD.bazel b/internal/BUILD.bazel
index e17ec48..d34df34 100644
--- a/internal/BUILD.bazel
+++ b/internal/BUILD.bazel
@@ -19,40 +19,48 @@
 exports_files([
     "worker_protocol.proto",
     # Exported to be consumed for generating skydoc.
-    "build_defs.bzl", "ts_config.bzl", "ts_repositories.bzl",
+    "build_defs.bzl",
+    "ts_config.bzl",
+    "ts_repositories.bzl",
 ])
 
 load("//internal:build_defs.bzl", "ts_library")
-load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary", "jasmine_node_test")
+load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test", "nodejs_binary")
 
 # Vanilla typescript compiler: run the tsc.js binary distributed by TypeScript
 nodejs_binary(
     name = "tsc",
-    node_modules = "@build_bazel_rules_typescript_tsc_wrapped_deps//:node_modules",
     entry_point = "typescript/lib/tsc.js",
+    node_modules = "@build_bazel_rules_typescript_tsc_wrapped_deps//:node_modules",
     visibility = ["//internal:__subpackages__"],
 )
 
 # Build our custom compiler using the vanilla one
 ts_library(
     name = "tsc_wrapped",
-    srcs = glob([
-      "tsc_wrapped/*.ts",
-      "tsetse/*.ts",
-      "tsetse/rules/*.ts"
-    ], exclude=["**/test_support.ts", "**/*_test.ts"]),
-    supports_workers = False,
+    srcs = glob(
+        [
+            "tsc_wrapped/*.ts",
+            "tsetse/*.ts",
+            "tsetse/rules/*.ts",
+        ],
+        exclude = [
+            "**/test_support.ts",
+            "**/*_test.ts",
+        ],
+    ),
     compiler = ":tsc",
-    node_modules = "@build_bazel_rules_typescript_tsc_wrapped_deps//:node_modules",
-    module_name = "@bazel/typescript",
-    module_root = "tsc_wrapped/index.d.ts",
-    tsconfig = "//internal:tsc_wrapped/tsconfig.json",
-    visibility = ["//visibility:public"],
     data = [
         # Should be @bazel_tools//src/main/protobuf:worker_protocol.proto
         # see https://github.com/bazelbuild/bazel/issues/3155#issuecomment-308156976
         ":worker_protocol.proto",
     ],
+    module_name = "@bazel/typescript",
+    module_root = "tsc_wrapped/index.d.ts",
+    node_modules = "@build_bazel_rules_typescript_tsc_wrapped_deps//:node_modules",
+    supports_workers = False,
+    tsconfig = "//internal:tsc_wrapped/tsconfig.json",
+    visibility = ["//visibility:public"],
     # Cannot have any deps because it doesn't work with vanilla tsc
     # Workaround for https://github.com/Microsoft/TypeScript/issues/22208
     deps = [
@@ -66,8 +74,8 @@
     data = [
         ":tsc_wrapped",
     ],
-    node_modules = "@build_bazel_rules_typescript_tsc_wrapped_deps//:node_modules",
     entry_point = "build_bazel_rules_typescript/internal/tsc_wrapped/tsc_wrapped.js",
+    node_modules = "@build_bazel_rules_typescript_tsc_wrapped_deps//:node_modules",
     templated_args = ["--node_options=--expose-gc"],
     visibility = ["//visibility:public"],
 )
@@ -75,8 +83,8 @@
 ts_library(
     name = "test_lib",
     srcs = glob(["tsc_wrapped/*_test.ts"]) + ["tsc_wrapped/test_support.ts"],
-    deps = [":tsc_wrapped"],
     tsconfig = "//internal:tsc_wrapped/tsconfig.json",
+    deps = [":tsc_wrapped"],
 )
 
 jasmine_node_test(
diff --git a/internal/build_defs.bzl b/internal/build_defs.bzl
index 359bd38..ac8ce12 100644
--- a/internal/build_defs.bzl
+++ b/internal/build_defs.bzl
@@ -27,13 +27,13 @@
     if output.basename.endswith(".externs.js"):
       externs_files.append(output)
     elif output.basename.endswith(".es5.MF"):
-      ctx.file_action(output, content="")
+      ctx.actions.write(output, content="")
     else:
       action_outputs.append(output)
 
   # TODO(plf): For now we mock creation of files other than {name}.js.
   for externs_file in externs_files:
-    ctx.file_action(output=externs_file, content="")
+    ctx.actions.write(output=externs_file, content="")
 
   # A ts_library that has only .d.ts inputs will have no outputs,
   # therefore there are no actions to execute
@@ -60,7 +60,7 @@
     arguments.append(tsconfig_file.path)
     mnemonic = "tsc"
 
-  ctx.action(
+  ctx.actions.run(
       progress_message = "Compiling TypeScript (%s) %s" % (description, ctx.label),
       mnemonic = mnemonic,
       inputs = action_inputs,
diff --git a/internal/common/compilation.bzl b/internal/common/compilation.bzl
index 6862427..4bd6077 100644
--- a/internal/common/compilation.bzl
+++ b/internal/common/compilation.bzl
@@ -90,9 +90,11 @@
 
   for dep in ctx.attr.deps + getattr(ctx.attr, '_helpers', []):
     if hasattr(dep, "typescript"):
-      direct_deps_declarations += dep.typescript.declarations
-      transitive_deps_declarations += dep.typescript.transitive_declarations
-      type_blacklisted_declarations += dep.typescript.type_blacklisted_declarations
+      # The TypeScript provider sometimes gives list and sometimes depset,
+      # so we wrap these in an extra depset() constructor
+      direct_deps_declarations = depset(transitive=[direct_deps_declarations, depset(dep.typescript.declarations)])
+      transitive_deps_declarations = depset(transitive=[transitive_deps_declarations, depset(dep.typescript.transitive_declarations)])
+      type_blacklisted_declarations = depset(transitive=[type_blacklisted_declarations, depset(dep.typescript.type_blacklisted_declarations)])
 
   # If a tool like github.com/angular/clutz can create .d.ts from type annotated .js
   # its output will be collected here.
@@ -125,9 +127,9 @@
     basename = "/".join(input_file.short_path.split("/")[trim:])
     dot = basename.rfind(".")
     basename = basename[:dot]
-    closure_js_files += [ctx.new_file(basename + ".closure.js")]
-    devmode_js_files += [ctx.new_file(basename + ".js")]
-    declaration_files += [ctx.new_file(basename + ".d.ts")]
+    closure_js_files += [ctx.actions.declare_file(basename + ".closure.js")]
+    devmode_js_files += [ctx.actions.declare_file(basename + ".js")]
+    declaration_files += [ctx.actions.declare_file(basename + ".d.ts")]
   return struct(
     closure_js = closure_js_files,
     devmode_js = devmode_js_files,
@@ -190,7 +192,7 @@
 
   if has_sources and ctx.attr.runtime != "nodejs":
     # Note: setting this variable controls whether tsickle is run at all.
-    tsickle_externs = [ctx.new_file(ctx.label.name + ".externs.js")]
+    tsickle_externs = [ctx.actions.declare_file(ctx.label.name + ".externs.js")]
 
   dep_declarations = _collect_dep_declarations(ctx)
   input_declarations = dep_declarations.transitive + src_declarations
@@ -217,11 +219,12 @@
   tsickle_externs_path = tsickle_externs[0] if tsickle_externs else None
 
   # Calculate allowed dependencies for strict deps enforcement.
-  allowed_deps = depset()
-  # A target's sources may depend on each other,
-  allowed_deps += srcs[:]
-  # or on a .d.ts from a direct dependency
-  allowed_deps += dep_declarations.direct
+  allowed_deps = depset(
+      # A target's sources may depend on each other,
+      srcs[:],
+      # or on a .d.ts from a direct dependency
+      transitive = [dep_declarations.direct],
+  )
 
   tsconfig_es6 = tsc_wrapped_tsconfig(
       ctx,
@@ -239,11 +242,11 @@
 
   node_profile_args = []
   if perf_trace and has_sources:
-    perf_trace_file = ctx.new_file(ctx.label.name + ".es6.trace")
+    perf_trace_file = ctx.actions.declare_file(ctx.label.name + ".es6.trace")
     tsconfig_es6["bazelOptions"]["perfTracePath"] = perf_trace_file.path
     outputs.append(perf_trace_file)
 
-    profile_file =  ctx.new_file(ctx.label.name + ".es6.v8.log")
+    profile_file =  ctx.actions.declare_file(ctx.label.name + ".es6.v8.log")
     node_profile_args = ["--prof",
                          # Without nologfile_per_isolate, v8 embeds an
                          # unpredictable hash code in the file name, which
@@ -252,9 +255,9 @@
                          "--logfile=" + profile_file.path]
     outputs.append(profile_file)
 
-    files += [perf_trace_file, profile_file]
+    files = depset(transitive=[files, [perf_trace_file, profile_file]])
 
-  ctx.file_action(output=ctx.outputs.tsconfig,
+  ctx.actions.write(output=ctx.outputs.tsconfig,
                   content=json_marshal(tsconfig_es6))
 
   # Parameters of this compiler invocation in case we need to replay this with different
@@ -266,8 +269,8 @@
     replay_params = compile_action(ctx, inputs, outputs, ctx.outputs.tsconfig,
                                    node_profile_args)
 
-    devmode_manifest = ctx.new_file(ctx.label.name + ".es5.MF")
-    tsconfig_json_es5 = ctx.new_file(ctx.label.name + "_es5_tsconfig.json")
+    devmode_manifest = ctx.actions.declare_file(ctx.label.name + ".es5.MF")
+    tsconfig_json_es5 = ctx.actions.declare_file(ctx.label.name + "_es5_tsconfig.json")
     outputs = (
         transpiled_devmode_js + gen_declarations + [devmode_manifest])
     tsconfig_es5 = tsc_wrapped_tsconfig(ctx,
@@ -278,11 +281,11 @@
                                         allowed_deps=allowed_deps)
     node_profile_args = []
     if perf_trace:
-      perf_trace_file = ctx.new_file(ctx.label.name + ".es5.trace")
+      perf_trace_file = ctx.actions.declare_file(ctx.label.name + ".es5.trace")
       tsconfig_es5["bazelOptions"]["perfTracePath"] = perf_trace_file.path
       outputs.append(perf_trace_file)
 
-      profile_file =  ctx.new_file(ctx.label.name + ".es5.v8.log")
+      profile_file =  ctx.actions.declare_file(ctx.label.name + ".es5.v8.log")
       node_profile_args = ["--prof",
                            # Without nologfile_per_isolate, v8 embeds an
                            # unpredictable hash code in the file name, which
@@ -291,9 +294,9 @@
                            "--logfile=" + profile_file.path]
       outputs.append(profile_file)
 
-      files += [perf_trace_file, profile_file]
+      files = depset(transitive=[files, [perf_trace_file, profile_file]])
 
-    ctx.file_action(output=tsconfig_json_es5, content=json_marshal(
+    ctx.actions.write(output=tsconfig_json_es5, content=json_marshal(
         tsconfig_es5))
     inputs = compilation_inputs + [tsconfig_json_es5]
     devmode_compile_action(ctx, inputs, outputs, tsconfig_json_es5,
@@ -312,22 +315,20 @@
     devmode_manifest = None
 
   # Downstream rules see the .d.ts files produced or declared by this rule.
-  declarations = depset()
-  declarations += gen_declarations
-  declarations += src_declarations
+  declarations = depset(gen_declarations + src_declarations)
   if not srcs:
     # Re-export sources from deps.
     # TODO(b/30018387): introduce an "exports" attribute.
     for dep in ctx.attr.deps:
       if hasattr(dep, "typescript"):
-        declarations += dep.typescript.declarations
-  files += declarations
+        declarations = depset(transitive=[declarations, dep.typescript.declarations])
+  files = depset(transitive=[files, declarations])
 
   # If this is a ts_declaration, add tsickle_externs to the outputs list to
   # force compilation of d.ts files.  (tsickle externs are produced by running a
   # compilation over the d.ts file and extracting type information.)
   if not is_library:
-    files += depset(tsickle_externs)
+    files = depset(tsickle_externs, transitive=[files])
 
   transitive_es5_sources = depset()
   transitive_es6_sources = depset()
diff --git a/internal/devserver/ts_devserver.bzl b/internal/devserver/ts_devserver.bzl
index 9ab325e..92f2fc8 100644
--- a/internal/devserver/ts_devserver.bzl
+++ b/internal/devserver/ts_devserver.bzl
@@ -25,9 +25,9 @@
   files = depset()
   for d in ctx.attr.deps:
     if hasattr(d, "node_sources"):
-      files += d.node_sources
+      files = depset(transitive=[files, d.node_sources])
     elif hasattr(d, "files"):
-      files += d.files
+      files = depset(transitive=[files, d.files])
 
   if ctx.label.workspace_root:
     # We need the workspace_name for the target being visited.
@@ -48,7 +48,7 @@
 
   amd_names_shim = ctx.actions.declare_file(
       "_%s.amd_names_shim.js" % ctx.label.name,
-      sibling = ctx.outputs.executable)
+      sibling = ctx.outputs.script)
   write_amd_names_shim(ctx.actions, amd_names_shim, ctx.attr.bootstrap)
 
   # Requirejs is always needed so its included as the first script
@@ -79,7 +79,7 @@
 
   # FIXME: more bash dependencies makes Windows support harder
   ctx.actions.write(
-      output = ctx.outputs.executable,
+      output = ctx.outputs.script,
       is_executable = True,
       content = """#!/bin/sh
 RUNFILES="$PWD/.."
@@ -101,11 +101,12 @@
     entry_module = ctx.attr.entry_module,
     port = str(ctx.attr.port)))
   return [DefaultInfo(
+      executable = ctx.outputs.script,
       runfiles = ctx.runfiles(
           files = devserver_runfiles,
           # We don't expect executable targets to depend on the devserver, but if they do,
           # they can see the JavaScript code.
-          transitive_files = depset(ctx.files.data) + files,
+          transitive_files = depset(ctx.files.data, transitive=[files]),
           collect_data = True,
           collect_default = True,
       )
@@ -153,6 +154,7 @@
         ),
     },
     outputs = {
+        "script": "%{name}.sh",
         "manifest": "%{name}.MF",
         "scripts_manifest": "scripts_%{name}.MF",
     },
diff --git a/internal/e2e/absolute_imports/BUILD.bazel b/internal/e2e/absolute_imports/BUILD.bazel
index 07a726f..fb25416 100644
--- a/internal/e2e/absolute_imports/BUILD.bazel
+++ b/internal/e2e/absolute_imports/BUILD.bazel
@@ -20,6 +20,6 @@
     name = "absolute_imports",
     srcs = glob(["*.ts"]),
     expected_diagnostics = [
-        "TS2307: Cannot find module 'internal/e2e/absolute_imports/foo'"
+        "TS2307: Cannot find module 'internal/e2e/absolute_imports/foo'",
     ],
 )
diff --git a/internal/karma/BUILD.bazel b/internal/karma/BUILD.bazel
index d2b5992..8802ef9 100644
--- a/internal/karma/BUILD.bazel
+++ b/internal/karma/BUILD.bazel
@@ -1,4 +1,4 @@
-package(default_visibility=["//visibility:public"])
+package(default_visibility = ["//visibility:public"])
 
 exports_files([
     "test-main.js",
@@ -21,7 +21,7 @@
 
 nodejs_binary(
     name = "karma_bin",
-    entry_point = "karma/bin/karma",
     data = [":karma_concat_js"],
+    entry_point = "karma/bin/karma",
     node_modules = "@build_bazel_rules_typescript_karma_deps//:node_modules",
 )
diff --git a/internal/karma/ts_web_test.bzl b/internal/karma/ts_web_test.bzl
index a6c69fc..d5213c4 100644
--- a/internal/karma/ts_web_test.bzl
+++ b/internal/karma/ts_web_test.bzl
@@ -26,14 +26,14 @@
 def _ts_web_test_impl(ctx):
   conf = ctx.actions.declare_file(
       "%s.conf.js" % ctx.label.name,
-      sibling=ctx.outputs.executable)
+      sibling=ctx.outputs.script)
 
   files = depset(ctx.files.srcs)
   for d in ctx.attr.deps:
     if hasattr(d, "node_sources"):
-      files += d.node_sources
+      files = depset(transitive=[files, d.node_sources])
     elif hasattr(d, "files"):
-      files += d.files
+      files = depset(transitive=[files, d.files])
 
   # The files in the bootstrap attribute come before the require.js support.
   # Note that due to frameworks = ['jasmine'], a few scripts will come before
@@ -49,7 +49,7 @@
 
   amd_names_shim = ctx.actions.declare_file(
       "_%s.amd_names_shim.js" % ctx.label.name,
-      sibling = ctx.outputs.executable)
+      sibling = ctx.outputs.script)
   write_amd_names_shim(ctx.actions, amd_names_shim, ctx.attr.bootstrap)
 
   # Explicitly list the requirejs library files here, rather than use
@@ -102,7 +102,7 @@
   karma_runfiles += ctx.files.static_files
 
   ctx.actions.write(
-      output = ctx.outputs.executable,
+      output = ctx.outputs.script,
       is_executable = True,
       content = """#!/usr/bin/env bash
 if [ -e "$RUNFILE_MANIFEST_FILE" ]; then
@@ -132,7 +132,7 @@
 """.format(TMPL_karma = karma_executable_path,
            TMPL_conf = conf.short_path))
   return [DefaultInfo(
-      files = depset([ctx.outputs.executable]),
+      files = depset([ctx.outputs.script]),
       runfiles = ctx.runfiles(
           files = karma_runfiles,
           transitive_files = files,
@@ -140,7 +140,7 @@
           collect_data = True,
           collect_default = True,
       ),
-      executable = ctx.outputs.executable,
+      executable = ctx.outputs.script,
   )]
 
 ts_web_test = rule(
@@ -178,6 +178,9 @@
             default = Label(_CONF_TMPL),
             allow_files = True, single_file = True),
     },
+    outputs = {
+        "script": "%{name}.sh",
+    },
 )
 """Runs unit tests in a browser.
 
diff --git a/internal/protobufjs/BUILD.bazel b/internal/protobufjs/BUILD.bazel
index 662c061..bfd588a 100644
--- a/internal/protobufjs/BUILD.bazel
+++ b/internal/protobufjs/BUILD.bazel
@@ -1,4 +1,5 @@
-package(default_visibility=["//visibility:public"])
+package(default_visibility = ["//visibility:public"])
+
 load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary")
 
 exports_files([
@@ -9,11 +10,12 @@
 
 nodejs_binary(
     name = "pbjs",
-    node_modules = "@build_bazel_rules_typescript_protobufs_compiletime_deps//:node_modules",
     entry_point = "protobufjs/bin/pbjs",
+    node_modules = "@build_bazel_rules_typescript_protobufs_compiletime_deps//:node_modules",
 )
+
 nodejs_binary(
     name = "pbts",
-    node_modules = "@build_bazel_rules_typescript_protobufs_compiletime_deps//:node_modules",
     entry_point = "protobufjs/bin/pbts",
+    node_modules = "@build_bazel_rules_typescript_protobufs_compiletime_deps//:node_modules",
 )
diff --git a/internal/ts_config.bzl b/internal/ts_config.bzl
index 95d5cbe..26f97e4 100644
--- a/internal/ts_config.bzl
+++ b/internal/ts_config.bzl
@@ -17,8 +17,7 @@
 TsConfigInfo = provider()
 
 def _ts_config_impl(ctx):
-  files = depset()
-  files += [ctx.file.src]
+  files = depset([ctx.file.src])
   return [DefaultInfo(files = files), TsConfigInfo(deps = ctx.files.deps)]
 
 ts_config = rule(
diff --git a/package.json b/package.json
index ffe5684..d8be67c 100644
--- a/package.json
+++ b/package.json
@@ -18,7 +18,6 @@
         "@types/node": "7.0.18",
         "@types/source-map": "^0.5.1",
         "@types/tmp": "^0.0.33",
-        "clang-format": "1.0.49",
         "concurrently": "^3.5.1",
         "http-server": "^0.11.1",
         "protobufjs": "5.0.0",
@@ -34,6 +33,8 @@
         "e2e-examples-app-prodserver": "concurrently \"bazel run examples/app:prodserver\" \"while ! nc -z 127.0.0.1 8080; do sleep 1; done && protractor --suite app\" --kill-others --success first",
         "e2e-examples-protobuf-devserver": "concurrently \"bazel run examples/protocol_buffers:devserver\" \"while ! nc -z 127.0.0.1 8080; do sleep 1; done && protractor --suite protocol_buffers\" --kill-others --success first",
         "e2e-examples-protobuf-prodserver": "concurrently \"bazel run examples/protocol_buffers:prodserver\" \"while ! nc -z 127.0.0.1 8080; do sleep 1; done && protractor --suite protocol_buffers\" --kill-others --success first",
+        "prebuildifier": "bazel build --noshow_progress @com_github_bazelbuild_buildtools//buildifier",
+        "buildifier": "find . -type f -name BUILD.bazel ! -path \"*/node_modules/*\" | xargs $(bazel info bazel-bin)/external/com_github_bazelbuild_buildtools/buildifier/*/buildifier",
         "preskylint": "bazel build --noshow_progress @io_bazel//src/tools/skylark/java/com/google/devtools/skylark/skylint:Skylint",
         "skylint": "find . -type f -name \"*.bzl\" ! -path \"*/node_modules/*\" | xargs $(bazel info bazel-bin)/external/io_bazel/src/tools/skylark/java/com/google/devtools/skylark/skylint/Skylint",
         "skydoc": "bazel build //:docs && unzip -o -d docs/api bazel-bin/docs-skydoc.zip"
diff --git a/yarn.lock b/yarn.lock
index 9c52425..1cc4d69 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -192,14 +192,6 @@
     strip-ansi "^3.0.0"
     supports-color "^2.0.0"
 
-clang-format@1.0.49:
-  version "1.0.49"
-  resolved "https://registry.yarnpkg.com/clang-format/-/clang-format-1.0.49.tgz#bf52f42277d41ed3618591f87145acf64aceb7e6"
-  dependencies:
-    async "^1.5.2"
-    glob "^7.0.0"
-    resolve "^1.1.6"
-
 cliui@^3.0.3:
   version "3.2.0"
   resolved "https://registry.yarnpkg.com/cliui/-/cliui-3.2.0.tgz#120601537a916d29940f934da3b48d585a39213d"
@@ -396,7 +388,7 @@
     once "^1.3.0"
     path-is-absolute "^1.0.0"
 
-glob@^7.0.0, glob@^7.0.3, glob@^7.0.5, glob@^7.0.6:
+glob@^7.0.3, glob@^7.0.5, glob@^7.0.6:
   version "7.1.2"
   resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.2.tgz#c19c9df9a028702d678612384a6552404c636d15"
   dependencies:
@@ -724,10 +716,6 @@
   version "1.0.2"
   resolved "https://registry.yarnpkg.com/path-is-inside/-/path-is-inside-1.0.2.tgz#365417dede44430d1c11af61027facf074bdfc53"
 
-path-parse@^1.0.5:
-  version "1.0.5"
-  resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.5.tgz#3c1adf871ea9cd6c9431b6ea2bd74a0ff055c4c1"
-
 performance-now@^2.1.0:
   version "2.1.0"
   resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b"
@@ -845,12 +833,6 @@
   version "1.0.0"
   resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff"
 
-resolve@^1.1.6:
-  version "1.3.3"
-  resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.3.3.tgz#655907c3469a8680dc2de3a275a8fdd69691f0e5"
-  dependencies:
-    path-parse "^1.0.5"
-
 rimraf@^2.2.8, rimraf@^2.5.2, rimraf@^2.5.4:
   version "2.6.2"
   resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.2.tgz#2ed8150d24a16ea8651e6d6ef0f47c4158ce7a36"