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

Added force_disable_services option to protobuf-ts/plugin for disabling service metadata generation #268

Merged
6 changes: 6 additions & 0 deletions packages/plugin/src/our-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ export interface InternalOptions {
readonly esLintDisable: boolean;
readonly transpileTarget: ts.ScriptTarget | undefined,
readonly transpileModule: ts.ModuleKind,
readonly disableServiceTypes: boolean;
readonly addPbSuffix: boolean;
}

Expand All @@ -227,6 +228,7 @@ export function makeInternalOptions(
client_none: boolean,
client_grpc1: boolean,
add_pb_suffix: boolean,
disable_service_types: boolean;
output_typescript: boolean,
output_javascript: boolean,
output_javascript_es2015: boolean,
Expand Down Expand Up @@ -265,6 +267,7 @@ export function makeInternalOptions(
esLintDisable: false,
transpileTarget: undefined,
transpileModule: ts.ModuleKind.ES2015,
disableServiceTypes: false,
addPbSuffix: false,
},
) as Writeable<InternalOptions>;
Expand Down Expand Up @@ -328,6 +331,9 @@ export function makeInternalOptions(
if (params?.add_pb_suffix) {
o.addPbSuffix = true;
}
if (params?.disable_service_types) {
o.disableServiceTypes = true;
}
if (params?.output_javascript) {
o.transpileTarget = ts.ScriptTarget.ES2020;
}
Expand Down
11 changes: 8 additions & 3 deletions packages/plugin/src/protobufts-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ export class ProtobuftsPlugin extends PluginBase {
"the default behaviour, this option has no effect.",
excludes: ['eslint_disable'],
},
disable_service_types: {
description: 'Prevents the generation of service metadata.',
},
ColinLaws marked this conversation as resolved.
Show resolved Hide resolved
add_pb_suffix: {
description: "Adds the suffix `_pb` to the names of all generated files. This will become the \n" +
"default behaviour in the next major release.",
Expand Down Expand Up @@ -309,10 +312,12 @@ export class ProtobuftsPlugin extends PluginBase {
if (DescriptorProto.is(descriptor)) {
genMessageType.generateMessageType(outMain, descriptor, optionResolver.getOptimizeMode(fileDescriptor));
}
if (ServiceDescriptorProto.is(descriptor)) {

// service type
genServiceType.generateServiceType(outMain, descriptor)
if (ServiceDescriptorProto.is(descriptor)) {
if (!options.disableServiceTypes) {
// service type
genServiceType.generateServiceType(outMain, descriptor);
}

// clients
const clientStyles = optionResolver.getClientStyles(descriptor);
Expand Down