protocolbuffers / protocolbuffers/protobuf-javascript

Generalize npm dependency support for generated js code

Open
#47 5 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

javascript triaged
Dominant language
JavaScript
Stars
471
Forks
91
Avg merge
3h 57m
Merged PRs (30d)
2

Description

Sister issue of https://github.com/grpc/grpc-web/issues/584 (copying content)

All generated code currently generates js import paths with similar structure with that of the imported .proto files.
The one exception for protobuf well-known types - google-protobuf based ont he import prefix:
https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/compiler/js/js_generator.cc#L128

string GetRootPath(const std::string& from_filename,
                   const std::string& to_filename) {
  if (to_filename.find("google/protobuf") == 0) {
    // Well-known types (.proto files in the google/protobuf directory) are
    // assumed to come from the 'google-protobuf' npm package.  We may want to
    // generalize this exception later by letting others put generated code in
    // their own npm packages.
    return "google-protobuf/";
  }

Equivalent code in grpc-web:
https://github.com/grpc/grpc-web/blob/master/javascript/net/grpc/web/grpc_generator.cc#L461

This will generate something like

import * as google_api_annotations_pb from './google/api/annotations_pb';
import * as google_protobuf_timestamp_pb from 'google-protobuf/google/protobuf/timestamp_pb';

An import option would allow users to explicitly override the relative path and specify a npm package at .proto import could be the right approach to generalize this.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing javascript/net/grpc/web/grpc_generator.cc around the referenced import-path logic with protobuf's src/google/protobuf/compiler/js/js_generator.cc. Determine the import option and package-path behavior needed to generalize the current google-protobuf exception. Done means generated imports can explicitly resolve dependencies from user-specified npm packages while preserving relative imports where no override is provided.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, javascript
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.