This repository was archived by the owner on Nov 18, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed
Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -168,10 +168,16 @@ export class GrpcClient {
168168 * when necessary.
169169 * @param {String } protoPath - The directory to search for the protofile.
170170 * @param {String|String[] } filename - The filename(s) of the proto(s) to be loaded.
171+ * If omitted, protoPath will be treated as a file path to load.
171172 * @return {Object<string, *> } The gRPC loaded result (the toplevel namespace
172173 * object).
173174 */
174- loadProto ( protoPath : string , filename : string | string [ ] ) {
175+ loadProto ( protoPath : string , filename ?: string | string [ ] ) {
176+ if ( ! filename ) {
177+ filename = path . basename ( protoPath ) ;
178+ protoPath = path . dirname ( protoPath ) ;
179+ }
180+
175181 if ( Array . isArray ( filename ) && filename . length === 0 ) {
176182 return { } ;
177183 }
Original file line number Diff line number Diff line change @@ -235,6 +235,17 @@ describe('grpc', () => {
235235 ) ;
236236 } ) ;
237237
238+ it ( 'should load the test file using single parameter syntax' , ( ) => {
239+ const fullPath = path . join ( TEST_PATH , TEST_FILE ) ;
240+ // no-any disabled because if the accessed fields are non-existent, this
241+ // test will fail anyway.
242+ // tslint:disable-next-line:no-any
243+ const protos = grpcClient . loadProto ( fullPath ) as any ;
244+ expect ( protos . google . example . library . v1 . LibraryService ) . to . be . a (
245+ 'Function'
246+ ) ;
247+ } ) ;
248+
238249 it ( 'should load a common proto' , ( ) => {
239250 const nonExistentDir = path . join ( __dirname , 'nonexistent' , 'dir' ) ;
240251 const iamService = path . join ( 'google' , 'iam' , 'v1' , 'iam_policy.proto' ) ;
You can’t perform that action at this time.
0 commit comments