Skip to content

Commit

Permalink
Meta tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Mar 26, 2019
1 parent da2d663 commit 6f68b21
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
25 changes: 12 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
'use strict';
const {promisify} = require('util');
const path = require('path');
const childProcess = require('child_process');
const util = require('util');
const isWsl = require('is-wsl');

const pExecFile = util.promisify(childProcess.execFile);
const pExecFile = promisify(childProcess.execFile);

// Converts a path from WSL format to Windows format
// e.g. /mnt/c/Program Files/Example/MyApp.exe
// => C:\Program Files\Example\MyApp.exe
// Convert a path from WSL format to Windows format:
// `/mnt/c/Program Files/Example/MyApp.exe` → `C:\Program Files\Example\MyApp.exe``
const wslToWindowsPath = async path => {
const {stdout} = await pExecFile('wslpath', ['-w', path]);
return stdout.trim();
Expand Down Expand Up @@ -55,8 +54,8 @@ module.exports = async (target, options) => {

if (options.app) {
if (isWsl && options.app.startsWith('/mnt/')) {
const winPath = await wslToWindowsPath(options.app);
options.app = winPath;
const windowsPath = await wslToWindowsPath(options.app);
options.app = windowsPath;
}

cliArguments.push(options.app);
Expand Down Expand Up @@ -91,24 +90,24 @@ module.exports = async (target, options) => {
cliArguments.push('--args', ...appArguments);
}

const cp = childProcess.spawn(command, cliArguments, childProcessOptions);
const subprocess = childProcess.spawn(command, cliArguments, childProcessOptions);

if (options.wait) {
return new Promise((resolve, reject) => {
cp.once('error', reject);
subprocess.once('error', reject);

cp.once('close', exitCode => {
subprocess.once('close', exitCode => {
if (exitCode > 0) {
reject(new Error(`Exited with code ${exitCode}`));
return;
}

resolve(cp);
resolve(subprocess);
});
});
}

cp.unref();
subprocess.unref();

return Promise.resolve(cp);
return subprocess;
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"is-wsl": "^1.1.0"
},
"devDependencies": {
"ava": "^1.3.1",
"ava": "^1.4.0",
"xo": "^0.24.0"
}
}
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ Default: `false`

Wait for the opened app to exit before fulfilling the promise. If `false` it's fulfilled immediately when opening the app.

Note that it waits for the app to exit, not just for the window to close.

On Windows, you have to explicitly specify an app for it to be able to wait.

##### app
Expand Down

0 comments on commit 6f68b21

Please sign in to comment.