From 6f68b21b2b39870c334982ea6655b539e3d282d0 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Wed, 27 Mar 2019 00:35:59 +0700 Subject: [PATCH] Meta tweaks --- index.js | 25 ++++++++++++------------- package.json | 2 +- readme.md | 2 ++ 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/index.js b/index.js index 5cb8cf4..3daa162 100644 --- a/index.js +++ b/index.js @@ -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(); @@ -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); @@ -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; }; diff --git a/package.json b/package.json index 0d3e85f..7774582 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "is-wsl": "^1.1.0" }, "devDependencies": { - "ava": "^1.3.1", + "ava": "^1.4.0", "xo": "^0.24.0" } } diff --git a/readme.md b/readme.md index 71cdbc8..2e17e7b 100644 --- a/readme.md +++ b/readme.md @@ -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