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

fix(typescript): add json to ts_project DefaultInfo, fix #1988 #1995

Merged
merged 3 commits into from
Jul 6, 2020

Conversation

longlho
Copy link
Contributor

@longlho longlho commented Jul 2, 2020

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature (please, look at the "Scope of the project" section in the README.md file)
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: #1988

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@longlho longlho marked this pull request as draft July 2, 2020 02:29
@longlho longlho marked this pull request as ready for review July 2, 2020 04:20
Copy link
Collaborator

@alexeagle alexeagle left a comment

Choose a reason for hiding this comment

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

LGTM after addressing the one main comment
thanks for the fix!

load("@build_bazel_rules_nodejs//:index.bzl", "generated_file_test")
load("//packages/typescript:index.bzl", "ts_project")

SRCS = glob(["**/*.ts*"]) + [
Copy link
Collaborator

Choose a reason for hiding this comment

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

aside: interesting pattern rather than ["**/*.ts", "**/*.tsx"] - I just wish the glob pattern allowed ["**/*.ts?"] so this wouldn't accidentally overmatch. But not much starts with "ts" so I'm considering adopting this in react projects...


json_outs = ctx.outputs.json_outs

# If there are no predeclared json_outs (probably bc of no .json or no outdir),
Copy link
Collaborator

Choose a reason for hiding this comment

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

this comment leaves an unanswered question: if there are no .json srcs and no .outdir then why do we need to declare any json_outs?
Is this load-bearing in some way? I pulled the change and your new test passes without this, so either remove it or make the test show why it's needed and update the comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so the predeclared json_outs outputs are only computed when both outdir is there as an attr & srcs contains json.

  • If there's no json, there's nothing to do.
  • If there're some jsons but outdir isn't there, tsc basically does a copy_to_bin-like behavior which is why the test passes for the no-outdir case (it grabs the src json instead of the copied one to compare?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated the test that should demo this :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

it still feels like this code is in the wrong place, compensating for json_outs having been passed into this function with the wrong value. Can it be fixed at the callsite instead? (line 402)
Seems like it just needs to match how js_outs is computed and passed in?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

initially I was doing just _join(outdir, f for f in srcs if f.endswith(".json")) but if outdir is None then I got input & output are the same. This is what special about json input :( For .ts u always get a .js output file but for json it's the same file if outdir isn't specified. Any rec on how to fix this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Right, makes sense, it's like copy_to_bin so you can't pre declare labels for outputs. What if we never declare them? (Degrade to common case for when outdir specified)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I tried just declare_file instead of splitting btwn predeclared outputs & declare_file but I can't get the path concat right for outdir, the file path in ctx.files.srcs seems to be the full path so I need some path mangling logic that I'm not sure if my assumptions are correct. Any guidance there?

Copy link
Collaborator

Choose a reason for hiding this comment

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

ah, I see, yes at this point the File object doesn't give you the path of the input relative to the package so you have to calculate it yourself
src.dirname[len(ctx.label.package)+1:]
I should have a commit to add here shortly...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

awesome thanks a lot!

@@ -389,6 +397,9 @@ def ts_project_macro(
tsconfig = tsconfig,
extends = extends,
outdir = outdir,
# JSON files are special. They are output if outdir is set since tsc will
# copy them to outdir. Otherwise they are kind of both.
Copy link
Collaborator

Choose a reason for hiding this comment

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

good explanation 👍 if tsc copies them to outdir then they are outputs of the action, easy justification

longlho and others added 2 commits July 4, 2020 20:51
@googlebot
Copy link

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: no and removed cla: yes labels Jul 5, 2020
@alexeagle
Copy link
Collaborator

@googlebot I consent.

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: yes and removed cla: no labels Jul 5, 2020
@alexeagle alexeagle merged commit 6c81478 into bazel-contrib:master Jul 6, 2020
@longlho longlho deleted the json branch July 6, 2020 01:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants