Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove usage of wslu #217

Merged
merged 1 commit into from Jan 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 5 additions & 30 deletions index.js
Expand Up @@ -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`');
Expand Down Expand Up @@ -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`;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is for standard Win32, where we may be running under Win7 where installing to a different location may be possible - luckily we can just fetch %SYSTEMROOT% here


cliArguments.push(
'-NoProfile',
'-NonInteractive',
Expand All @@ -79,9 +61,7 @@ module.exports = async (target, options) => {
'-EncodedCommand'
);

if (isWsl) {
command = await windowsToWslPath(command);
} else {
if (!isWsl) {
childProcessOptions.windowsVerbatimArguments = true;
}

Expand All @@ -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');
Expand Down