improbable-eng/ts-protoc-gen

Question: bundling generated files as npm package

jvmlet opened this issue · 2 comments

Hello
What would be the recommended approach to package all generated js files as npm package while exporting all modules.
Thanks

Hi @jvmlet, sorry for the slow response.

You can package up the generated output in as an npm module by adding the following package.json to in the root directory of the generated output (ie: the proto folder), ensuring that you declare dependencies on google-protobuf and its typedefs:

{
  "name": "my-protos",
  "version": "1.0.0",
  "description": "",
  "dependencies": {
    "@types/google-protobuf": "^3.2.7",
    "google-protobuf": "^3.8.0-rc.1"
  }
}

Following an npm install, your directory structure should look something like this:

├── node_modules
├── orphan_pb.d.ts
├── orphan_pb.js
├── orphan_pb_service.d.ts
├── orphan_pb_service.js
├── package-lock.json
└── package.json

Now, in the consumer package, you will be able to declare a dependency on the my-protos package as you would any other module and import using the following syntax:

import { OrphanStreamRequest } from 'my-protos/orphan_pb';

Please let me know if you have any followup questions.

is this supported when generating PBs/RPCs for multiple protos in different/nested directories?