Skip to content

Commit

Permalink
fix(twilio-run:start): makes readfile async, uses cli.cwd
Browse files Browse the repository at this point in the history
  • Loading branch information
philnash committed Aug 31, 2020
1 parent dd96f73 commit c53ea6b
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions packages/twilio-run/src/config/start.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { EnvironmentVariables } from '@twilio-labs/serverless-api';
import dotenv from 'dotenv';
import { readFileSync } from 'fs';
import { readFile } from 'fs';
import { promisify } from 'util';
const readFilePromise = promisify(readFile);
import path, { resolve, join } from 'path';
import { homedir } from 'os';
import { Arguments, config } from 'yargs';
import { Arguments } from 'yargs';
import { ExternalCliOptions, SharedFlags } from '../commands/shared';
import { CliInfo } from '../commands/types';
import { EnvironmentVariablesWithAuth } from '../types/generic';
Expand Down Expand Up @@ -75,9 +77,9 @@ export async function getUrl(cli: StartCliFlags, port: string | number) {
if (typeof cli.ngrokConfig === 'string') {
// If we set a config path then try to load that config. If the config
// fails to load then we'll try to load the default config instead.
const configPath = join(process.cwd(), cli.ngrokConfig);
const configPath = join(cli.cwd || process.cwd(), cli.ngrokConfig);
try {
ngrokConfig = parse(readFileSync(configPath, 'utf-8'));
ngrokConfig = parse(await readFilePromise(configPath, 'utf-8'));
} catch (err) {
logger.warn(`Could not find ngrok config file at ${configPath}`);
}
Expand All @@ -87,7 +89,7 @@ export async function getUrl(cli: StartCliFlags, port: string | number) {
// `ngrokConfig` to be an empty object.
const configPath = join(homedir(), '.ngrok2', 'ngrok.yml');
try {
ngrokConfig = parse(readFileSync(configPath, 'utf-8'));
ngrokConfig = parse(await readFilePromise(configPath, 'utf-8'));
} catch (err) {
ngrokConfig = {};
}
Expand Down Expand Up @@ -167,7 +169,7 @@ export async function getEnvironment(
if (await fileExists(fullEnvPath)) {
try {
debug(`Read .env file at "%s"`, fullEnvPath);
const envContent = readFileSync(fullEnvPath, 'utf8');
const envContent = await readFilePromise(fullEnvPath, 'utf8');
const envValues = dotenv.parse(envContent);
for (const [key, val] of Object.entries(envValues)) {
env[key] = val;
Expand Down

0 comments on commit c53ea6b

Please sign in to comment.