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

RFC: The future of this package #145

Open
jonnyreeves opened this issue Dec 13, 2018 · 9 comments
Open

RFC: The future of this package #145

jonnyreeves opened this issue Dec 13, 2018 · 9 comments
Labels

Comments

@jonnyreeves
Copy link
Contributor

jonnyreeves commented Dec 13, 2018

Overview

This package (ts-protoc-gen) has always conflated two distinct use-cases:

  1. Generate TypeScript definitions (.d.ts) to accompany the JavaScript generated by protoc
  2. Generate the JavaScript and TypeScript definitions for use with improbable-eng/grpc-web

In the light of recent forks, such as adding support for flowtype, I feel it may be wise to consider splitting these two use-cases out into two distinct protoc plugins.

  1. protoc-gen-tsd (usage: --tsd_out=$OUT)
  2. protoc-gen-improbable-grpc-web (usage: --improbable-grpc-web_out=dts:$OUT)

This renaming would also help create a distinction between the official grpc-web offering from google, and the improbable-eng/grpc-web offering from Improbable.

Migration Path

  1. This repo (and associated npm package) could potentially continue to exist and wrap protoc-gen-tsd and protoc-gen-improbable-grpc-web to avoid breaking consumer workflows until such a point that they can be deprecated and migrated.
  2. The code would need to be split; I can see two possible approaches:
    a.) Create 2 or more repositories under improbable-eng for each protoc plugin (and possibly one for shared code)
    b.) Create a single mono-repository using a tool like lerna to manage the node modules.

Misc

It may make more sense to join efforts with agreatfool/grpc_tools_node_protoc_ts (cc @agreatfool) who has built out their own protoc compiler for generating TypeScript definitions. Although a full audit of feature-sets would need to follow.

cc @easyCZ @MarcusLongmuir @johanbrandhorst @chrisgervang

@johanbrandhorst
Copy link
Contributor

Great initiative, agreed that it will be a good thing for users to have more clarity on these two use cases.

@jonnyreeves
Copy link
Contributor Author

Calling @Dig-Doug, @coltonmorris as our resident bazel experts; please could you help me understand the implications of splitting ts-protoc-gen into 2 distinct tools (see overview above) with regards to the bazel build rules in this repo? Your input on how to manage such a migration would be appreciated.

@jonnyreeves
Copy link
Contributor Author

I've created the above issue in the grpc/grpc-web project to see if we can avoid creating the protoc-gen-tsd plugin mentioned in this issues overview.

@Dig-Doug
Copy link
Contributor

There are two main parts to the current bazel setup:

  1. Rules needed to build the protoc plugins under bazel, e.g. this target

  2. Rules for generating typescript definitions and services stubs, mostly in this file

# 1

No matter how you split up your protoc plugins, the new repo structure will need to have the bazel setup (replacing # 1) to run them in # 2. Looking at your suggestions, I don't see any issues with either a) or b): bazel can pull in tools from multiple repos or reference mutliple tools from the same repo.

With respect to migrating, this code is all internal. Clients shouldn't be referencing these targets directly.

# 2

Based on the new structure, the code for # 2 will need to be updated to point to the new tools (e.g. here). This code can live in a different repo1 than the plugins or in the same repo. Note that the rules need to reference all of the plugins, so make sure the rules are in a place that doesn't cause circular dependencies.

Migrating: This code is what clients interact with. While the API of the rules won't be changing, the location will. For clients, this means changing the WORKSPACE file:

http_archive(
    # NOTE: The name should be changed to match new location
    name = "<new-name>",
    urls = ["https://github.com/<new-location>"],
)

and load calls in BUILD files:

# NOTE: Since the http_archive's name has changed, load calls need to be updated:
load("@<new-name>//:defs.bzl", "typescript_proto_library")

Once you have decided on the location of the new rules, you can also add a warning to the existing implementation that they're deprecated. The warning will get printed during the build. However, clients will only see this warning if they've updated the rules to a later version.

1 I noticed the other day that the rules_proto library is referencing the ts-protoc-gen code here -- though I don't think it currently works. rules_protobuf and its successor, rules_proto, is a popular library for using protos/grpc with bazel. If you'd like to split out the bazel rules in addition to the protoc plugins, you should consider moving them there.

jonny-improbable added a commit to improbable-eng/grpc-web that referenced this issue Mar 8, 2019
Proof of concept protoc-plugin for generating service clients for use with @improbable-eng/grpc-web.

## Why?
See conversation in improbable-eng/ts-protoc-gen#145

## Design Choices
1. This package uses [protoc-plugin](https://github.com/konsumer/node-protoc-plugin) which provides the ability to [extract comments from the source proto](https://github.com/konsumer/node-protoc-plugin#findcommentbypath) and in-line them into the generated code; this was a much requested feature on ts-protoc-gen

2. [ts-morph](https://dsherret.github.io/ts-morph/) is used to build TypeScript source code in-line; this is then compiled into TypeScript definition files (`.d.ts`) and JavaScript source files. This is great as it reduces the number of code-paths required.

## What's left to do?
Loads, off the top of my head:

1. Generate service clients, at present we are only generating classes required to use directly against grpc-web ("Raw!")
2. Add unit/integration test coverage!
3. Add support for in-lined documentation from source protos.
@stale
Copy link

stale bot commented Mar 16, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@Dig-Doug
Copy link
Contributor

Update on this: Recently there have been some new features added to rules_nodejs that could eliminate the need to have any bazel setup in this repo.

I took a look at the issues today and noticed that there are a bunch related to the bazel rules, not the protoc plugin. With the current setup it's a bit difficult for me to keep an eye on open issues, PRs, etc. @jonnyreeves - I was wondering what you think of me moving the bazel rules to a separate repository?

@jonnyreeves
Copy link
Contributor Author

jonnyreeves commented Oct 20, 2019 via email

@Dig-Doug
Copy link
Contributor

Great, I have created rules_typescript_proto and submitted a PR to clean up the code here.

@Raiondesu
Copy link

Is this issue still relevant?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants