Skip to content

Commit 1bb9f9d

Browse files
committed
fix(twilio-run:start): makes readfile async, uses cli.cwd
1 parent d549fbb commit 1bb9f9d

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

packages/twilio-run/src/config/start.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { EnvironmentVariables } from '@twilio-labs/serverless-api';
22
import dotenv from 'dotenv';
3-
import { readFileSync } from 'fs';
3+
import { readFile } from 'fs';
4+
import { promisify } from 'util';
5+
const readFilePromise = promisify(readFile);
46
import path, { resolve, join } from 'path';
57
import { homedir } from 'os';
6-
import { Arguments, config } from 'yargs';
8+
import { Arguments } from 'yargs';
79
import { ExternalCliOptions, SharedFlags } from '../commands/shared';
810
import { CliInfo } from '../commands/types';
911
import { 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

Comments
 (0)