rules_nodejs icon indicating copy to clipboard operation
rules_nodejs copied to clipboard

npm_package_bin forwards DeclarationInfo, causing unconditional type-checks of its data

Open alexeagle opened this issue 2 years ago • 1 comments

Context on bazel slack: https://bazelbuild.slack.com/archives/CEZUUKQ6P/p1642975005112800?thread_ts=1642607496.083900&cid=CEZUUKQ6P

https://github.com/bazelbuild/rules_nodejs/blob/stable/internal/node/npm_package_bin.bzl#L46-L47 means that if any data dep has a DeclarationInfo, it will be requested from that target and cause type-checking where it's not needed.

The easy fix is to just stop propagating the DeclarationInfo as inputs to the tool. However there are probably some cases where the .d.ts files from that provider are actually required for that tool to run. Also we have to be sensitive to breaking changes.

Workaround:

make a file rules_nodejs.patch with content

index 49d0cd80e..6ce21b7ef 100644
--- internal/node/npm_package_bin.bzl
+++ internal/node/npm_package_bin.bzl
@@ -43,8 +43,8 @@ def _inputs(ctx):
             inputs_depsets.append(d[ExternalNpmPackageInfo].sources)
         if JSModuleInfo in d:
             inputs_depsets.append(d[JSModuleInfo].sources)
-        if DeclarationInfo in d:
-            inputs_depsets.append(d[DeclarationInfo].declarations)
+        #if DeclarationInfo in d:
+        #    inputs_depsets.append(d[DeclarationInfo].declarations)
     return depset(ctx.files.data, transitive = inputs_depsets).to_list()
 
 def _impl(ctx):

and then add patches = ["//:rules_nodejs.patch"], to your http_archive(name = "build_bazel_rules_nodejs")

alexeagle avatar Jan 24 '22 14:01 alexeagle

This issue has been automatically marked as stale because it has not had any activity for 6 months. It will be closed if no further activity occurs in 30 days. Collaborators can add a "cleanup" or "need: discussion" label to keep it open indefinitely. Thanks for your contributions to rules_nodejs!

github-actions[bot] avatar Jul 27 '22 03:07 github-actions[bot]

This issue was automatically closed because it went 30 days without any activity since it was labeled "Can Close?"

github-actions[bot] avatar Aug 26 '22 03:08 github-actions[bot]