File tree Expand file tree Collapse file tree 3 files changed +33
-3
lines changed
protoc-plugin-helpers/src Expand file tree Collapse file tree 3 files changed +33
-3
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ type PrinterProtobufOptions =
1414 | { protobuf : "ts-proto" } ;
1515
1616export type PrinterCommonOptions = {
17+ emitImportedFiles : boolean ;
1718 importPrefix : string | null ;
1819 fileLayout : FileLayout ;
1920 filenameSuffix : string ;
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ export function parseParams<DSL extends PrinterOptions["dsl"]>(
2222 dsl,
2323 protobuf : "google-protobuf" ,
2424 importPrefix : null ,
25+ emitImportedFiles : false ,
2526 fileLayout : "proto_file" ,
2627 filenameSuffix : dsl === "nexus" ? "_pb_nexus.ts" : ".pb.pothos.ts" ,
2728 pothos : { builderPath : "./builder" } ,
@@ -61,6 +62,9 @@ export function parseParams<DSL extends PrinterOptions["dsl"]>(
6162 case "partial_inputs" :
6263 params . type . partialInputs = toBool ( k , v ) ;
6364 break ;
65+ case "emit_imported_files" :
66+ params . printer . emitImportedFiles = toBool ( k , v ) ;
67+ break ;
6468 case "file_layout" : {
6569 const s = toString ( k , v ) ;
6670 if ( ! checkEnum ( s , fileLayouts ) ) {
Original file line number Diff line number Diff line change @@ -32,9 +32,7 @@ export function createProcessor<DSL extends PrinterOptions["dsl"]>({
3232
3333 const params = parseParams ( req . getParameter ( ) , dsl ) ;
3434
35- for ( const fn of req . getFileToGenerateList ( ) ) {
36- const file = registry . findFile ( fn ) ;
37- if ( file == null ) throw new Error ( `${ fn } is not found` ) ;
35+ for ( const file of getFilesToGenerate ( req , registry ) ) {
3836 const results = generateFiles ( registry , file , params ) ;
3937
4038 for ( const result of results ) {
@@ -48,3 +46,30 @@ export function createProcessor<DSL extends PrinterOptions["dsl"]>({
4846 return resp ;
4947 } ;
5048}
49+
50+ function getFilesToGenerate (
51+ req : CodeGeneratorRequest ,
52+ reg : ProtoRegistry
53+ ) : ProtoFile [ ] {
54+ const filesToGenerateSet = new Set ( req . getFileToGenerateList ( ) ) ;
55+ return req
56+ . getProtoFileList ( )
57+ . map ( ( f ) => f . getName ( ) )
58+ . filter ( isDefined )
59+ . filter ( ( n ) => filesToGenerateSet . has ( n ) )
60+ . map ( ( n ) => reg . findFile ( n ) )
61+ . filter ( isNotNull )
62+ . filter ( ( f ) => ! isWellKnownTypesFile ( f ) ) ;
63+ }
64+
65+ function isDefined < V > ( v : V | undefined ) : v is V {
66+ return v !== undefined ;
67+ }
68+
69+ function isNotNull < V > ( v : V | null ) : v is V {
70+ return v !== null ;
71+ }
72+
73+ function isWellKnownTypesFile ( f : ProtoFile ) : boolean {
74+ return f . name . startsWith ( "google/protobuf/" ) ;
75+ }
You can’t perform that action at this time.
0 commit comments