Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

Expose providers/api for rules and tool building #227

Closed
yohcop opened this issue Jul 3, 2018 · 2 comments
Closed

Expose providers/api for rules and tool building #227

yohcop opened this issue Jul 3, 2018 · 2 comments

Comments

@yohcop
Copy link

yohcop commented Jul 3, 2018

In trying to write a packaging rule for all the typescript sources in a project, I was looking for a way to list all the typescript sources needed by a given ts_library.

I couldn't really find anything though. For example, rules_go has a documented set of providers. I was able to use GoArchive.transitive to place all the required files in a set of runfiles, for the packaging tool.

Is there something similar for rules_typescript? (Even if undocumented, I can bear the pain of updating my rules when things change ;))

@alexeagle
Copy link
Contributor

I aspire to have nice docs like that for providers. I've been investing in skydoc, I'll have to see if there's some way to generate such docs from sources.

In the meantime, you can see what a ts_library's "typescript" provider has
https://github.com/bazelbuild/rules_typescript/blob/master/internal/common/compilation.bzl#L361
but none of these is meant to give you the original TypeScript files. Why would you want them?

Check out extra action listeners
#54
and aspects as a couple of out-of-band ways to perform some action on all ts_library targets without needing to interact with outputs of the rule.

@yohcop
Copy link
Author

yohcop commented Jul 10, 2018

Hi Alex,

The reason I wanted them, was to be able to create a source tree, with all the original .ts and .tsx files, so I could run webpack on them.

I found a workaround though. Since I was using my own "ts_lib" macro, wrapping "ts_library" (so I didn't have to specify the tsconfig everywhere -- this was from the early days of rules_typescript, things may have changed now), I made my ts_lib macro not only wrap ts_library, but also a filegroup, which includes as srcs the sources of the ts_library, and also all the dependencies of the ts_library. This way, the :app ts_lib, also generate a :app_filegroup target, which includes all transitive dependencies. I can use this target as dependency for the genrule running webpack.

This worked great since I already had the ts_lib macro used everywhere. And in a way, I'm looking forward to getting rid of this as soon as rules_closure/rules_typescript are working together (#6) to build the prod js binary. Right now, I'm essentially building things twice, with webpack and with rules_typescript, which is a waste and slow.

Anyway, closing this. Feel free to keep as a feature request. I still think it would be nice to have the sources and transitive sources available. It can be useful for other tools. For example graphql-code-generator can search your sources for gql`` strings, and generate typings. -- The same trick above worked for that, but it would be a pain if I didn't already have this macro used everywhere.

@yohcop yohcop closed this as completed Jul 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants