Skip to content

Commit

Permalink
Merge branch 'fix-spawn' into v3
Browse files Browse the repository at this point in the history
  • Loading branch information
philnash committed Mar 14, 2021
2 parents e58488c + 61f9187 commit c254851
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions process.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const { promisify } = require("util")
const { join } = require("path");
const { spawn, exec: execCallback } = require('child_process');
const exec = promisify(execCallback);
const platform = require('os').platform();

const defaultDir = __dirname + '/bin';
const bin = './ngrok' + (platform === 'win32' ? '.exe' : '');
const defaultDir = join(__dirname, 'bin');
const bin = 'ngrok' + (platform === 'win32' ? '.exe' : '');
const ready = /starting web service.*addr=(\d+\.\d+\.\d+\.\d+:\d+)/;
const inUse = /address already in use/;

Expand Down Expand Up @@ -35,7 +36,7 @@ async function startProcess (opts) {
if (opts.configPath) start.push('--config=' + opts.configPath);
if (opts.binPath) dir = opts.binPath(dir);

const ngrok = spawn(bin, start, {cwd: dir});
const ngrok = spawn(join(dir, bin), start);

let resolve, reject;
const apiUrl = new Promise((res, rej) => {
Expand Down Expand Up @@ -114,7 +115,8 @@ async function setAuthtoken (optsOrToken) {

let dir = defaultDir;
if (opts.binPath) dir = opts.binPath(dir)
const ngrok = spawn(bin, authtoken, {cwd: dir});

const ngrok = spawn(join(dir, bin), authtoken);

const killed = new Promise((resolve, reject) => {
ngrok.stdout.once('data', () => resolve());
Expand All @@ -135,7 +137,7 @@ async function setAuthtoken (optsOrToken) {
async function getVersion(opts = {}) {
let dir = defaultDir;
if (opts.binPath) dir = opts.binPath(dir);
const { stdout } = await exec(`${bin} --version`, { cwd: dir });
const { stdout } = await exec(`${join(dir, bin)} --version`);
return stdout.replace('ngrok version', '').trim();
}

Expand Down

0 comments on commit c254851

Please sign in to comment.