-
Notifications
You must be signed in to change notification settings - Fork 522
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
Allow JSON files to be used as modules in ts_library #2264
Conversation
e04452a
to
b459952
Compare
You checked the box in the PR description for "tests added" but I don't see them here. Could you add a .json input under whichever existing packages/typescript/tests/* seems most appropriate and some assertion of what you expect to happen, like that the program type-checks or that the json file got copied to the output tree? |
Ugh, sorry, I completely missed that I didn't I've added some tests, but I'd appreciate some pointers for testing some of the mechanical pieces. For instance, I'd love to verify that the build fails if I give a |
Fudge, this might not be enough. I might also have to change the tsc_wrapped to not emit JSON. Right now, if I build the However, if I build
It's weird to me I don't get that every time, but it's coming from If I change And to note: I cannot allow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah your error does indicate a problem. If the file already exists in the output tree we aren't allowed to overwrite it unless we declare as an output.
The contract from tsc is that .json inputs are written to the output tree, so the correct thing to do under Bazel is to model it the same way. However as you point out we currently have these two different hard-coded output flavors in ts_library
which is a big project to fix. (and maybe not worth it if ts_project catches up)
My guess is the flavor that outputs .d.ts
files should also output .json
files - I think that's the es5_sources
output (devmode_compile_action)
I suppose hacking tsc_wrapped
as a workaround is acceptable. It's just another admission that ts_library
diverged from tsc
in a way we can't fix with the resources we have to work on in.
}) | ||
|
||
# Unless this is set true, manually prevent JSON in the srcs attribute. | ||
if not kwargs.get("allow_json_srcs", False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you add some explanation why we need this, rather than always allow .json in srcs now?
I'm going to close this. Given what we last discussed, there's a bit more thought that needs put into it for what's best with For now we're using a local fork, and will either merge forward to |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
ts_library does not allow you to have a JSON file as a source, nor does it let you import from them.
Issue Number: #1109
What is the new behavior?
Adds a
allow_json_srcs
attr tots_library
for those who would like to use JSON as source files (assuming the user'stsconfig
and chosenmodule
output types allow it).If
allow_json_srcs
is not supplied,ts_library
should effectively have no change.Does this PR introduce a breaking change?
Other information
I wasn't sure what files to update for documentation, and I understand if this isn't something y'all want to take on.