From: Mike Lothian <mike@fireburn.co.uk>
Subject: [PATCH] Fallback to system node and local tsc in devtools typescript runner

When bundled typescript is not available, look for typescript in
devtools node_modules and invoke with system node.
---
--- a/third_party/devtools-frontend/src/third_party/typescript/typescript.py
+++ b/third_party/devtools-frontend/src/third_party/typescript/typescript.py
@@ -9,7 +9,7 @@
 import os


-def GetBinaryPath():
+def GetBinaryCommand():
     if platform.machine() == 'arm64':
         darwin_path = 'mac-arm64'
     else:
@@ -23,16 +23,25 @@

     devtools_checkout_path = os_path.join(os_path.dirname(__file__), *relative)
     if os_path.exists(devtools_checkout_path):
-        return os_path.normpath(devtools_checkout_path)
+        return [os_path.normpath(devtools_checkout_path)]

     # Assume we are in a chromium checkout.
-    return os_path.normpath(
+    chromium_path = os_path.normpath(
         os_path.join(os_path.dirname(__file__), '..', '..', '..', '..',
                      'typescript', *relative))
+    if os_path.exists(chromium_path):
+        return [chromium_path]
+
+    devtools_root = os_path.normpath(
+        os_path.join(os_path.dirname(__file__), '..', '..'))
+    node_modules_tsc = os_path.join(devtools_root, 'node_modules', 'typescript', 'bin', 'tsc')
+    sys.path.append(os_path.join(devtools_root, 'scripts'))
+    import devtools_paths
+    return [devtools_paths.node_path(), node_modules_tsc]


 def RunTypeScriptRaw(cmd_parts, stdout=None):
-    cmd = [GetBinaryPath()] + cmd_parts
+    cmd = GetBinaryCommand() + cmd_parts
     process = subprocess.Popen(cmd,
                                cwd=os.getcwd(),
                                stdout=subprocess.PIPE,
@@ -54,7 +63,7 @@
             # example https://github.com/microsoft/TypeScript/issues/615
             errs.append("stdout:\n" + stdout)
         errs.append("exit=%d" % code)
-        cmd = [GetBinaryPath()] + cmd_parts
+        cmd = GetBinaryCommand() + cmd_parts
         raise RuntimeError('Command \'%s\' failed\n%s' %
                            (' '.join(cmd), '\n'.join(errs)))
     return stdout
--- a/third_party/devtools-frontend/src/scripts/build/typescript/typescript_vars.gni
+++ b/third_party/devtools-frontend/src/scripts/build/typescript/typescript_vars.gni
@@ -6,7 +6,7 @@
 import("../ninja/vars.gni")

 if (host_os == "linux") {
-  tsc_binary = "//third_party/typescript/linux-amd64/src/lib/tsc"
+  tsc_binary = devtools_location_prepend + "node_modules/typescript/bin/tsc"
 } else if (host_os == "win") {
   tsc_binary = "//third_party/typescript/windows-amd64/src/lib/tsc.exe"
 } else if (host_os == "mac") {
