Fix compilation of //internal/tsc_wrapped

PiperOrigin-RevId: 157155278
diff --git a/internal/BUILD.oss b/internal/BUILD.oss
index 33605dd..71ad008 100644
--- a/internal/BUILD.oss
+++ b/internal/BUILD.oss
@@ -14,11 +14,4 @@
 
 package(default_visibility = ["//visibility:public"])
 
-load(":node.bzl", "node_binary")
-
-node_binary(
-    name = "tsc_wrapped",
-    data = ["@yarn//installed:node_modules"],
-    # TODO(alexeagle): plug in tsc_wrapped.js instead
-    main = "yarn/installed/node_modules/typescript/lib/tsc.js",
-)
+exports_files(["node_launcher.sh"])
diff --git a/internal/build_defs.bzl b/internal/build_defs.bzl
index 3e0f4c5..8af987e 100644
--- a/internal/build_defs.bzl
+++ b/internal/build_defs.bzl
@@ -45,7 +45,7 @@
       inputs=action_inputs,
       outputs=non_externs_files,
       arguments=["-p", config_file_path],
-      executable=ctx.executable._tsc)
+      executable=ctx.executable.tsc)
 
 
 def _devmode_compile_action(ctx, inputs, outputs, config_file_path):
@@ -75,11 +75,7 @@
   workspace_path = "/".join([".."] * len(tsconfig_json.dirname.split("/")))
   host_bin = "bazel-out/host/bin"
 
-  if ctx.workspace_name == "io_bazel_rules_typescript":
-    runfiles = "internal/tsc_wrapped.runfiles"
-  else:
-    runfiles = "external/io_bazel_rules_typescript/internal/tsc_wrapped.runfiles"
-
+  runfiles = ctx.executable.tsc.short_path + ".runfiles"
   module_roots = {
       "*": [
           "/".join([host_bin, runfiles, "yarn/installed/node_modules/*"]),
@@ -162,7 +158,7 @@
             attr.label(allow_files = True, single_file=True),
         "_additional_d_ts":
             attr.label_list(),
-        "_tsc":
+        "tsc":
             attr.label(
                 default=get_tsc(),
                 single_file=False,
diff --git a/internal/executables.bzl b/internal/executables.bzl
index 95844d3..68e07bc 100644
--- a/internal/executables.bzl
+++ b/internal/executables.bzl
@@ -16,7 +16,7 @@
 """
 
 def get_tsc():
-  return Label("//internal:tsc_wrapped")
+  return Label("//internal/tsc_wrapped:tsc_wrapped_bin")
 
 def get_node():
   return Label("@io_bazel_rules_typescript_node//:bin/node")
diff --git a/internal/tsc_wrapped/BUILD.oss b/internal/tsc_wrapped/BUILD.oss
index 46754d2..26972ce 100644
--- a/internal/tsc_wrapped/BUILD.oss
+++ b/internal/tsc_wrapped/BUILD.oss
@@ -1,7 +1,44 @@
-load("//:defs.bzl", "ts_library")
+# Copyright 2017 The Bazel Authors. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
 
+load("//:defs.bzl", "ts_library")
+load("//internal:node.bzl", "node_binary")
+
+# Vanilla typescript compiler: run the tsc.js binary distributed by TypeScript
+node_binary(
+    name = "tsc",
+    data = ["@yarn//installed:node_modules"],
+    main = "yarn/installed/node_modules/typescript/lib/tsc.js",
+)
+
+# Build our custom compiler using the vanilla one
 ts_library(
   name = "tsc_wrapped",
   srcs = glob(["*.ts"]),
   tsconfig = ":tsconfig.json",
+  tsc = ":tsc",
+)
+
+# Other ts_library rules will use this custom compiler, which calls the
+# TypeScript APIs to act like tsc, but adds capabilities like Bazel workers.
+node_binary(
+    name = "tsc_wrapped_bin",
+    data = [
+      ":tsc_wrapped",
+      "@yarn//installed:node_modules",
+    ],
+    # TODO(alexeagle): plug in tsc_wrapped.js instead
+    main = "yarn/installed/node_modules/typescript/lib/tsc.js",
+    visibility = ["//visibility:public"],
 )