Skip to content

feat: copy proto .d.ts back to source tree#2766

Open
alexeagle wants to merge 2 commits intomainfrom
diff.bzl.d.ts
Open

feat: copy proto .d.ts back to source tree#2766
alexeagle wants to merge 2 commits intomainfrom
diff.bzl.d.ts

Conversation

@alexeagle
Copy link
Member

This is a missing feature compared with the now-deprecated ts_proto_library

Thanks to @kormide for getting the new diff.bzl out the door!

@aspect-workflows

This comment was marked as off-topic.

@github-actions

This comment was marked as outdated.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ad5473a234

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@jbedard jbedard requested a review from kormide March 11, 2026 22:40
js/proto.bzl Outdated
**kwargs
)

def js_proto_library(name, proto, copy_types = None):
Copy link
Member

Choose a reason for hiding this comment

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

Can't the proto target have many proto files? Doesn't that mean we need to output many "types" files?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, but I'm also hoping to avoid making the user repeat the list of output files like we did in rules_ts... working on it

Copy link
Member

@kormide kormide left a comment

Choose a reason for hiding this comment

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

LGTM. Will let @jbedard approve.

in deps attribute of starlark_doc_extract rule //js:proto.doc_extract: missing bzl_library targets for
Starlark module(s) @diff.bzl//:diff.bzl

Did I mess up the bzl_library targets in diff.bzl?

@alexeagle
Copy link
Member Author

alexeagle commented Mar 11, 2026

@kormide

Did I mess up the bzl_library targets in diff.bzl

no, it's the same pattern as the other *.bzl modules - the syntax sugar is for end users, rules should use the @diff.bzl//diff:defs.bzl load statement for stardocs. Updated here.

gen_file = "_{}.gen_{}.d.ts".format(name, i)
diff_target = "{}.diff_{}".format(name, i)
select_file(name = gen_file, srcs = "_{}.types".format(name), subpath = src_file)
diff(
Copy link
Member

Choose a reason for hiding this comment

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

@kormide did you guys think about any APIs to support multiple files?

Copy link
Member

Choose a reason for hiding this comment

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

Not yet. Open to suggestions. @alexeagle and I are also discussing async.


def _js_proto_library_impl(ctx):
return [
OutputGroupInfo(types = ctx.attr.proto[JsInfo].types),
Copy link
Member

Choose a reason for hiding this comment

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

Is it ok this has no DefaultInfo(files) with the JsInfo.sources like js_library does?

I think having no DefaultInfo(runfiles) is probably correct though? Or that might be a discussion+test for another day...

@jbedard
Copy link
Member

jbedard commented Mar 12, 2026

You can rebase/pull to get my workaround for the bazel 9.0.1 issue (pinning to 9.0.0 for now).

def js_proto_library(name, proto, copy_types = []):
"""Wrap a proto_library to invoke the js_proto_toolchain.

Can copy .d.ts type definitions back to the source folder.
Copy link
Contributor

Choose a reason for hiding this comment

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

Will users want to create a js_proto_library() for every proto_library(), so that all .d.ts files get copied back to the source folder? This makes me wonder if js_proto_library() should use an aspect for this, so that you can get all the .d.ts files copied over without needing to replicate the whole proto_library dependency graph.

Copy link
Member Author

Choose a reason for hiding this comment

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

Users probably do want a lang_proto_library for each proto_library, that's already the common practice and it's Gazelle's job to create those targets in the BUILD file.

If we only wanted to have an aspect on a js_library -> proto_library edge, we already have one of those. I could experiment with the DX of doing it without any js_proto_library targets in the BUILD file.

I'll get an example landed first so we can base our PRs from that.

Also fix a bug where `js_library` deps ran the proto aspect, but
js_binary/js_test did not.

/cc @acozzette
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants