From 27da7890fc3d18d8f9647ed41b3a5212a2f03fbc Mon Sep 17 00:00:00 2001 From: Greg Magolan Date: Thu, 6 Jun 2024 15:32:34 -0700 Subject: [PATCH] chore(bazel): fixup custom eslint test rule after bump to rules_js 2 (#63143) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This regressed in https://github.com/sourcegraph/sourcegraph/pull/63022 where the custom `gather_files_from_js_providers` function that was copied over from rules_js 1.x was including runfiles. Resolves eslint failures seen in https://buildkite.com/sourcegraph/sourcegraph/builds/277072#018fe743-abac-44d8-911b-d5a7ed425413 and observed locally: ``` (07:19:15) INFO: From ESLint client/wildcard/wildcard_lib_eslint-output.txt:   |     | Oops! Something went wrong! :(   |     | ESLint: 8.57.0   |     | ESLint couldn't find a configuration file. To set up a configuration file for this project, please run:   |     | npm init @eslint/config   |     | ESLint looked for configuration files in /tmp/bazel-working-directory/__main__/bazel-out/k8-fastbuild/bin/client/wildcard/src/components/Alert and its ancestors. If it found none, it then looked in your home directory.   |     | If you think you already have a configuration file or if you need more help, please stop by the ESLint Discord server: https://eslint.org/chat ``` ## Test plan CI (check test logs) ## Changelog --- dev/eslint.bzl | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/dev/eslint.bzl b/dev/eslint.bzl index b3f0e8c40b4..cab12d382b3 100644 --- a/dev/eslint.bzl +++ b/dev/eslint.bzl @@ -56,17 +56,26 @@ def eslint_config_and_lint_root(name = "eslint_config", config_deps = [], root_j def _custom_eslint_impl(ctx): copied_srcs = copy_files_to_bin_actions(ctx, ctx.files.srcs) - inputs_depset = depset( + input_targets = [ctx.attr.config] + ctx.attr.deps + + input_depsets = [depset( copied_srcs + [ctx.executable.binary], transitive = [js_lib_helpers.gather_files_from_js_infos( - targets = [ctx.attr.config] + ctx.attr.deps, - include_sources = False, + targets = input_targets, + include_sources = True, # include sources & transitives sources so the eslint config .js files are picked up include_types = True, # we have to include types because we need to lint the types. - include_transitive_sources = False, + include_transitive_sources = True, # include sources & transitives sources so the eslint config .js files are picked up include_transitive_types = True, # we have to include types because we need to lint the types. include_npm_sources = True, )], - ) + )] + + # include runfiles in inputs as well so they can be resolved from the execroot + input_depsets.extend([ + target[DefaultInfo].default_runfiles.files + for target in input_targets + if DefaultInfo in target and hasattr(target[DefaultInfo], "default_runfiles") + ]) runfiles = js_lib_helpers.gather_runfiles( ctx = ctx, @@ -118,7 +127,7 @@ def _custom_eslint_impl(ctx): # Generate and run a bash script to wrap the binary ctx.actions.run_shell( env = env, - inputs = inputs_depset, + inputs = depset([], transitive = input_depsets), outputs = [report, exit_code_out], command = command, arguments = [args],