File tree Expand file tree Collapse file tree 3 files changed +17
-16
lines changed Expand file tree Collapse file tree 3 files changed +17
-16
lines changed Original file line number Diff line number Diff line change @@ -196,11 +196,13 @@ describe('options', () => {
196196 describe ( 'parseFileOption' , ( ) => {
197197 it ( 'parses file' , ( ) => {
198198 expect (
199- parseFileOption ( join ( __dirname , 'fixtures' , 'synthetics.config.ts' ) )
199+ parseFileOption ( 'test' ) (
200+ join ( __dirname , 'fixtures' , 'synthetics.config.ts' )
201+ )
200202 ) . toBeInstanceOf ( Buffer ) ;
201203 } ) ;
202204 it ( 'parses string' , ( ) => {
203- expect ( parseFileOption ( 'test' ) ) . toEqual ( 'test' ) ;
205+ expect ( parseFileOption ( 'test' ) ( 'test' ) ) . toEqual ( 'test' ) ;
204206 } ) ;
205207 } ) ;
206208
Original file line number Diff line number Diff line change @@ -305,12 +305,12 @@ program
305305 . option (
306306 '--proxy-ca <path>' ,
307307 'provide a CA override for proxy endpoint, as a path to be loaded or as string' ,
308- collectOpts ( 'ca' , proxySettings , parseFileOption )
308+ collectOpts ( 'ca' , proxySettings , parseFileOption ( '--proxy-ca' ) )
309309 )
310310 . option (
311311 '--proxy-cert <path>' ,
312312 'provide a cert override for proxy endpoint, as a path to be loaded or as string' ,
313- collectOpts ( 'cert' , proxySettings , parseFileOption )
313+ collectOpts ( 'cert' , proxySettings , parseFileOption ( '--proxy-cert' ) )
314314 )
315315 . option (
316316 '--proxy-no-verify' ,
Original file line number Diff line number Diff line change @@ -28,7 +28,6 @@ import { createOption } from 'commander';
2828import { readConfig } from './config' ;
2929import type { CliArgs , RunOptions } from './common_types' ;
3030import { isFile , THROTTLING_WARNING_MSG , warn } from './helpers' ;
31- import path from 'path' ;
3231import { readFileSync } from 'fs' ;
3332
3433type Mode = 'run' | 'push' ;
@@ -305,18 +304,18 @@ function parseAsBuffer(value: any): Buffer {
305304 }
306305}
307306
308- export function parseFileOption ( value : string ) {
309- const filePath = path . resolve ( value ) ;
310-
311- if ( ! isFile ( filePath ) ) {
312- return value ;
313- }
307+ export function parseFileOption ( opt : string ) {
308+ return ( value : string ) => {
309+ if ( ! isFile ( value ) ) {
310+ return value ;
311+ }
314312
315- try {
316- return readFileSync ( filePath ) ;
317- } catch ( e ) {
318- throw new Error ( `could not be read provided path ${ filePath } : ${ e } ` ) ;
319- }
313+ try {
314+ return readFileSync ( value ) ;
315+ } catch ( e ) {
316+ throw new Error ( `${ opt } - could not read provided path ${ value } : ${ e } ` ) ;
317+ }
318+ } ;
320319}
321320
322321// This is a generic util to collect multiple options into a single
You can’t perform that action at this time.
0 commit comments