From ae0743ba911ee79c1330f71d8ba0181dc081ce5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ana=C3=AFs=20Betts?= Date: Fri, 29 Jan 2021 13:59:37 +0100 Subject: [PATCH] Remove usage of wslu This PR is simplified version of #198 - Windows 10 does not allow installing the OS to locations other than C:\Windows so fetching %systemroot% is unnecessary here (and since WSL is exclusive to Windows 10, we do not need to worry about Win7 here). WSL also handles marshaling paths between WSL and Windows, so we don't need to convert this path manually. --- index.js | 35 +++++------------------------------ 1 file changed, 5 insertions(+), 30 deletions(-) diff --git a/index.js b/index.js index 9ee4a0c..8ff4034 100644 --- a/index.js +++ b/index.js @@ -7,30 +7,10 @@ const isWsl = require('is-wsl'); const isDocker = require('is-docker'); const pAccess = promisify(fs.access); -const pExecFile = promisify(childProcess.execFile); // Path to included `xdg-open`. const localXdgOpenPath = path.join(__dirname, 'xdg-open'); -// 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(); -}; - -// Convert a path from Windows format to WSL format -const windowsToWslPath = async path => { - const {stdout} = await pExecFile('wslpath', [path]); - return stdout.trim(); -}; - -// Get an environment variable from Windows -const wslGetWindowsEnvVar = async envVar => { - const {stdout} = await pExecFile('wslvar', [envVar]); - return stdout.trim(); -}; - module.exports = async (target, options) => { if (typeof target !== 'string') { throw new TypeError('Expected a `target`'); @@ -69,8 +49,10 @@ module.exports = async (target, options) => { cliArguments.push('-a', app); } } else if (process.platform === 'win32' || (isWsl && !isDocker())) { - const windowsRoot = isWsl ? await wslGetWindowsEnvVar('systemroot') : process.env.SYSTEMROOT; - command = String.raw`${windowsRoot}\System32\WindowsPowerShell\v1.0\powershell${isWsl ? '.exe' : ''}`; + command = isWsl ? + '/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe' : + `${process.env.SYSTEMROOT}\\System32\\WindowsPowerShell\\v1.0\\powershell`; + cliArguments.push( '-NoProfile', '-NonInteractive', @@ -79,9 +61,7 @@ module.exports = async (target, options) => { '-EncodedCommand' ); - if (isWsl) { - command = await windowsToWslPath(command); - } else { + if (!isWsl) { childProcessOptions.windowsVerbatimArguments = true; } @@ -92,11 +72,6 @@ module.exports = async (target, options) => { } if (app) { - if (isWsl && app.startsWith('/')) { - const windowsPath = await wslToWindowsPath(app); - app = windowsPath; - } - // Double quote with double quotes to ensure the inner quotes are passed through. // Inner quotes are delimited for PowerShell interpretation with backticks. encodedArguments.push(`"\`"${app}\`""`, '-ArgumentList');