Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support For Typecheck-Only Validation Action #574

Closed

Conversation

jacobgardner
Copy link
Contributor

@jacobgardner jacobgardner commented Mar 26, 2024


Type of change

  • New feature or functionality (change which adds functionality)

My attempt at fixing #88 as a validation action.

For changes visible to end-users

  • Breaking change (this change will force users to change their own code or config)

    • Requires bazel 6 or higher for validation action support.
    • Removes some warnings about typecheck only not being supported.
  • Relevant documentation has been updated

  • Suggested release notes are provided below:
    ts_project no longer needs to emit declaration files in order to work with a non-tsc transpiler. If no declaration emit and no transpilation takes place, tsc --noEmit is still run as a validation action.

Test plan

  • Covered by existing test cases
  • New test cases added

jfirebaugh pushed a commit to jfirebaugh/rules_ts that referenced this pull request Apr 11, 2024
@jfirebaugh
Copy link
Contributor

@jacobgardner Thanks for working on this! I tested it out in our repo at Figma, and it works well. I did have to make an addition on top of your changes, to support an explicit no_emit attribute for ts_project, which we needed for our use case. (It's a bit niche, but we have two ts_project targets with overlapping .ts inputs, each typechecking with a different tsconfig. These targets are to be used only for typechecking and linting. Our bundler is a separate target.) My additions are here: jfirebaugh@f5df77c

@jacobgardner
Copy link
Contributor Author

Sweet. I will merge your changes in soon.

@jacobgardner
Copy link
Contributor Author

I merged the no_emit code. I want to add some tests for that later this week as well though.

@jfirebaugh
Copy link
Contributor

I've found another hiccup with this approach: when using it in tandem with rules_lint / aspect lint, the typechecking actions will trigger even when you're just trying to run eslint. This is because the validations output group "is special in that its outputs are always requested, regardless of the value of the --output_groups flag, and regardless of how the target is depended upon" (https://bazel.build/extending/rules#validations_output_group).

I think perhaps aspect lint should pass --run_validations=false to the underlying bazel command it runs? Or provide a hook so that we can add that in .bazelrc. For example aspect lint could run bazel build --config=lint ... and then I could put config:lint --run_validations=false in .bazelrc.

Copy link

aspect-workflows bot commented Apr 24, 2024

Test

⚠️ GitHub Actions build #446 failed.

Failed tests (1)
//docs:update_0_test [k8-fastbuild] 80ms

💡 To reproduce the test failures, run

bazel test //docs:update_0_test

Buildifier      Format

@jfirebaugh
Copy link
Contributor

jfirebaugh commented May 2, 2024

A more serious issue with this approach is that it negates the performance optimization of using ts_project#transpiler to avoid typechecking in situations when only the transpiled outputs are necessary. The behavior of validation actions makes typechecking always eager again.

Is a validation action actually providing value in this case? It still requires a "marker" output. Could we instead just have a normal action that outputs the same marker?

@@ -133,6 +134,7 @@ function ts_project() {
local source_map=""
local declaration=""
local composite=""
local tranpsiler=""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
local tranpsiler=""
local transpiler=""

@@ -146,6 +148,7 @@ function ts_project() {
--source-map) shift; source_map="source_map = True," ;;
--declaration) shift; declaration="declaration = True," ;;
--composite) shift; composite="composite = True," ;;
--mockTranspiler) shift; composite="transpiler = mock," ;;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
--mockTranspiler) shift; composite="transpiler = mock," ;;
--mockTranspiler) shift; transpiler="transpiler = mock," ;;

And then $transpiler should be inserted in the appropriate place in the heredoc string below.

alexeagle added a commit to aspect-build/rules_lint that referenced this pull request May 9, 2024
alexeagle added a commit to aspect-build/rules_lint that referenced this pull request May 10, 2024
* fix: lint.sh pass norun_validations

See aspect-build/rules_ts#574 (comment)

* Update lint.sh
run_cmd = "{} $@".format(executable.path)
arguments.add_all(["--bazelValidationFile", validation_output.short_path])
else:
run_cmd = """{} $@ && echo "" > {} """.format(executable.path, validation_output.path)
Copy link
Member

@alexeagle alexeagle Sep 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of echo "" could we just use https://github.com/aspect-build/rules_js/blob/main/js/private/js_binary.sh.tpl#L22 - merely adding JS_BINARY__STDOUT_OUTPUT_FILE to the env of this action will yield a useful "marker file"

@alexeagle
Copy link
Member

Replaced by #681 where @jbedard has picked up your commits

@alexeagle alexeagle closed this Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants