Remove types[node] from compilation of tsc_wrapped

This is needed for compatibility with new ts_library rule impl which includes typings found in deps[] as files in the program

Closes #456

PiperOrigin-RevId: 253243590
diff --git a/internal/tsc_wrapped/tsconfig.json b/internal/tsc_wrapped/tsconfig.json
index d3f2772..830ed18 100644
--- a/internal/tsc_wrapped/tsconfig.json
+++ b/internal/tsc_wrapped/tsconfig.json
@@ -2,7 +2,13 @@
   "compilerOptions": {
     "strict": true,
     "types": [
-      "node",
+      // Normally "node" should be listed here since we depend on it.
+      // However this library is built with vanilla tsc.
+      // Since the deps[] are passed into the ts.Program as files
+      // (starting with https://github.com/bazelbuild/rules_nodejs/pull/756)
+      // we cannot also list node as a types[] since vanilla tsc will load
+      // both into the program and get a conflict.
+      // Under tsc_wrapped this isn't a problem since we control the resolution.
     ],
     "lib": [
       "dom",
diff --git a/package.bzl b/package.bzl
index f31ab0c..e75064b 100644
--- a/package.bzl
+++ b/package.bzl
@@ -30,6 +30,10 @@
     _maybe(
         http_archive,
         name = "build_bazel_rules_nodejs",
+        # This file just copy-pasted from output of `git diff`
+        patches = ["//:rules_nodejs_pr756.patch"],
+        # According to docs, this is needed for patches generated by git
+        patch_args = ["-p1"],
         sha256 = "e04a82a72146bfbca2d0575947daa60fda1878c8d3a3afe868a8ec39a6b968bb",
         urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.31.1/rules_nodejs-0.31.1.tar.gz"],
     )
diff --git a/rules_nodejs_pr756.patch b/rules_nodejs_pr756.patch
new file mode 100644
index 0000000..9db35b3
--- /dev/null
+++ b/rules_nodejs_pr756.patch
@@ -0,0 +1,30 @@
+--- a/internal/npm_install/node_module_library.bzl
++++ b/internal/npm_install/node_module_library.bzl
+@@ -29,14 +29,20 @@ def _node_module_library_impl(ctx):
+     # use in rules such as ts_devserver
+     scripts = depset(ctx.files.scripts)
+ 
+-    # declarations are a subset of sources that are decleration files
+-    declarations = depset([f for f in ctx.files.srcs if f.path.endswith(".d.ts")])
++    # declarations are a subset of sources that are declaration files
++
++    declarations = depset([
++        f
++        for f in ctx.files.srcs
++        if f.path.endswith(".d.ts") and
++           # exclude eg. external/npm/node_modules/protobufjs/node_modules/@types/node/index.d.ts
++           # these would be duplicates of the typings provided directly in another dependency
++           len(f.path.split("/node_modules/")) < 3
++    ])
++
++    # transitive_declarations are all .d.ts files in srcs plus those in direct & transitive dependencies
++    transitive_declarations = depset(transitive = [declarations])
+ 
+-    # transitive_declarations are all direct & transitive decleration files
+-    transitive_declarations = depset()
+-    for src in ctx.attr.srcs:
+-        if hasattr(src, "typescript"):
+-            transitive_declarations = depset(transitive = [transitive_declarations, src.typescript.transitive_declarations])
+     for dep in ctx.attr.deps:
+         if hasattr(dep, "typescript"):
+             transitive_declarations = depset(transitive = [transitive_declarations, dep.typescript.transitive_declarations])