Skip to content

Commit

Permalink
feat: implemented emitImportedFiles flag
Browse files Browse the repository at this point in the history
Fixes stephenh#294.
This commit puts changes from stephenh#283 behind the flag.
  • Loading branch information
doochik committed May 22, 2021
1 parent c89d3f7 commit b64d851
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ protoc --plugin=node_modules/ts-proto/protoc-gen-ts_proto ./batching.proto -I.

- With `--ts_proto_opt=outputServices=grpc-js`, ts-proto will output service definitions and server / client stubs in [grpc-js](https://github.com/grpc/grpc-node/tree/master/packages/grpc-js) format.

- With `--ts_proto_opt=emitImportedFiles=false`, ts-proto will not emit `google/protobuf/*` files unless you explicit add files to `protoc` like this
`protoc --plugin=./node_modules/.bin/protoc-gen-ts_proto my_message.proto google/protobuf/duration.proto`

### Only Types

If you're looking for `ts-proto` to generate only types for your Protobuf types then passing all three of `outputEncodeMethods`, `outputJsonMethods`, and `outputClientImpl` as `false` is probably what you want, i.e.:
Expand Down
2 changes: 2 additions & 0 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export type Options = {
outputSchema: boolean;
// An alias of !output
onlyTypes: boolean;
emitImportedFiles: boolean;
};

export function defaultOptions(): Options {
Expand Down Expand Up @@ -77,6 +78,7 @@ export function defaultOptions(): Options {
exportCommonSymbols: true,
outputSchema: false,
onlyTypes: false,
emitImportedFiles: true,
};
}

Expand Down
3 changes: 2 additions & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ async function main() {
const utils = makeUtils(options);
const ctx: Context = { typeMap, options, utils };

const filesToGenerate = options.emitImportedFiles ? request.protoFile : protoFilesToGenerate(request);
const files = await Promise.all(
protoFilesToGenerate(request).map(async (file) => {
filesToGenerate.map(async (file) => {
const [path, code] = generateFile(ctx, file);
const spec = await code.toStringWithImports({ ...getTsPoetOpts(options), path });
return { name: path, content: prefixDisableLinter(spec) };
Expand Down
1 change: 1 addition & 0 deletions tests/options-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe('options', () => {
"addNestjsRestParameter": false,
"constEnums": false,
"context": false,
"emitImportedFiles": true,
"env": "both",
"esModuleInterop": false,
"exportCommonSymbols": true,
Expand Down

0 comments on commit b64d851

Please sign in to comment.