Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: sindresorhus/open
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v7.3.1
Choose a base ref
...
head repository: sindresorhus/open
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v7.4.0
Choose a head ref
  • 2 commits
  • 2 files changed
  • 2 contributors

Commits on Jan 30, 2021

  1. Remove usage of wslu (#217)

    anaisbetts authored Jan 30, 2021

    Verified

    This commit was signed with the committer’s verified signature.
    dtolnay David Tolnay
    Copy the full SHA
    315a480 View commit details

Commits on Feb 1, 2021

  1. 7.4.0

    sindresorhus committed Feb 1, 2021

    Verified

    This commit was signed with the committer’s verified signature.
    dtolnay David Tolnay
    Copy the full SHA
    5ce319c View commit details
Showing with 6 additions and 31 deletions.
  1. +5 −30 index.js
  2. +1 −1 package.json
35 changes: 5 additions & 30 deletions index.js
Original file line number Diff line number Diff line change
@@ -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');
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "open",
"version": "7.3.1",
"version": "7.4.0",
"description": "Open stuff like URLs, files, executables. Cross-platform.",
"license": "MIT",
"repository": "sindresorhus/open",