1
1
import { EnvironmentVariables } from '@twilio-labs/serverless-api' ;
2
2
import dotenv from 'dotenv' ;
3
- import { readFileSync } from 'fs' ;
3
+ import { readFile } from 'fs' ;
4
+ import { promisify } from 'util' ;
5
+ const readFilePromise = promisify ( readFile ) ;
4
6
import path , { resolve , join } from 'path' ;
5
7
import { homedir } from 'os' ;
6
- import { Arguments , config } from 'yargs' ;
8
+ import { Arguments } from 'yargs' ;
7
9
import { ExternalCliOptions , SharedFlags } from '../commands/shared' ;
8
10
import { CliInfo } from '../commands/types' ;
9
11
import { EnvironmentVariablesWithAuth } from '../types/generic' ;
@@ -75,9 +77,9 @@ export async function getUrl(cli: StartCliFlags, port: string | number) {
75
77
if ( typeof cli . ngrokConfig === 'string' ) {
76
78
// If we set a config path then try to load that config. If the config
77
79
// 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 ) ;
79
81
try {
80
- ngrokConfig = parse ( readFileSync ( configPath , 'utf-8' ) ) ;
82
+ ngrokConfig = parse ( await readFilePromise ( configPath , 'utf-8' ) ) ;
81
83
} catch ( err ) {
82
84
logger . warn ( `Could not find ngrok config file at ${ configPath } ` ) ;
83
85
}
@@ -87,7 +89,7 @@ export async function getUrl(cli: StartCliFlags, port: string | number) {
87
89
// `ngrokConfig` to be an empty object.
88
90
const configPath = join ( homedir ( ) , '.ngrok2' , 'ngrok.yml' ) ;
89
91
try {
90
- ngrokConfig = parse ( readFileSync ( configPath , 'utf-8' ) ) ;
92
+ ngrokConfig = parse ( await readFilePromise ( configPath , 'utf-8' ) ) ;
91
93
} catch ( err ) {
92
94
ngrokConfig = { } ;
93
95
}
@@ -167,7 +169,7 @@ export async function getEnvironment(
167
169
if ( await fileExists ( fullEnvPath ) ) {
168
170
try {
169
171
debug ( `Read .env file at "%s"` , fullEnvPath ) ;
170
- const envContent = readFileSync ( fullEnvPath , 'utf8' ) ;
172
+ const envContent = await readFilePromise ( fullEnvPath , 'utf8' ) ;
171
173
const envValues = dotenv . parse ( envContent ) ;
172
174
for ( const [ key , val ] of Object . entries ( envValues ) ) {
173
175
env [ key ] = val ;
0 commit comments