11import { EnvironmentVariables } from '@twilio-labs/serverless-api' ;
22import dotenv from 'dotenv' ;
3- import { readFileSync } from 'fs' ;
3+ import { readFile } from 'fs' ;
4+ import { promisify } from 'util' ;
5+ const readFilePromise = promisify ( readFile ) ;
46import path , { resolve , join } from 'path' ;
57import { homedir } from 'os' ;
6- import { Arguments , config } from 'yargs' ;
8+ import { Arguments } from 'yargs' ;
79import { ExternalCliOptions , SharedFlags } from '../commands/shared' ;
810import { CliInfo } from '../commands/types' ;
911import { EnvironmentVariablesWithAuth } from '../types/generic' ;
@@ -75,9 +77,9 @@ export async function getUrl(cli: StartCliFlags, port: string | number) {
7577 if ( typeof cli . ngrokConfig === 'string' ) {
7678 // If we set a config path then try to load that config. If the config
7779 // fails to load then we'll try to load the default config instead.
78- const configPath = join ( process . cwd ( ) , cli . ngrokConfig ) ;
80+ const configPath = join ( cli . cwd || process . cwd ( ) , cli . ngrokConfig ) ;
7981 try {
80- ngrokConfig = parse ( readFileSync ( configPath , 'utf-8' ) ) ;
82+ ngrokConfig = parse ( await readFilePromise ( configPath , 'utf-8' ) ) ;
8183 } catch ( err ) {
8284 logger . warn ( `Could not find ngrok config file at ${ configPath } ` ) ;
8385 }
@@ -87,7 +89,7 @@ export async function getUrl(cli: StartCliFlags, port: string | number) {
8789 // `ngrokConfig` to be an empty object.
8890 const configPath = join ( homedir ( ) , '.ngrok2' , 'ngrok.yml' ) ;
8991 try {
90- ngrokConfig = parse ( readFileSync ( configPath , 'utf-8' ) ) ;
92+ ngrokConfig = parse ( await readFilePromise ( configPath , 'utf-8' ) ) ;
9193 } catch ( err ) {
9294 ngrokConfig = { } ;
9395 }
@@ -167,7 +169,7 @@ export async function getEnvironment(
167169 if ( await fileExists ( fullEnvPath ) ) {
168170 try {
169171 debug ( `Read .env file at "%s"` , fullEnvPath ) ;
170- const envContent = readFileSync ( fullEnvPath , 'utf8' ) ;
172+ const envContent = await readFilePromise ( fullEnvPath , 'utf8' ) ;
171173 const envValues = dotenv . parse ( envContent ) ;
172174 for ( const [ key , val ] of Object . entries ( envValues ) ) {
173175 env [ key ] = val ;
0 commit comments