From 9b6800d1c366847faceab4eeab9a55d247c11889 Mon Sep 17 00:00:00 2001 From: Dean Sheather Date: Wed, 5 Jun 2019 15:03:34 +1000 Subject: [PATCH 1/2] add executable check for local xdg-open --- index.js | 17 ++++++++++++++--- package.json | 1 + 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index d791638..95637f7 100644 --- a/index.js +++ b/index.js @@ -2,12 +2,16 @@ const {promisify} = require('util'); const path = require('path'); const childProcess = require('child_process'); +const isExe = require('executable'); const isWsl = require('is-wsl'); 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`` +// `/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(); @@ -76,8 +80,15 @@ module.exports = async (target, options) => { // When bundled by Webpack, there's no actual package file path and no local `xdg-open`. const isBundled = !__dirname || __dirname === '/'; - const useSystemXdgOpen = process.versions.electron || process.platform === 'android' || isBundled; - command = useSystemXdgOpen ? 'xdg-open' : path.join(__dirname, 'xdg-open'); + // Check if local `xdg-open` exists and is executable. + let exeLocalXdgOpen = false; + try { + exeLocalXdgOpen = await isExe(localXdgOpenPath); + } catch (error) {} + + const useSystemXdgOpen = process.versions.electron || + process.platform === 'android' || isBundled || !exeLocalXdgOpen; + command = useSystemXdgOpen ? 'xdg-open' : localXdgOpenPath; } if (appArguments.length > 0) { diff --git a/package.json b/package.json index 8f6fdbe..f9a7077 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "file" ], "dependencies": { + "executable": "^4.1.1", "is-wsl": "^1.1.0" }, "devDependencies": { From 97d863873f6cf355ea3567b85cefc4cbd79b48fe Mon Sep 17 00:00:00 2001 From: Dean Sheather Date: Thu, 27 Jun 2019 13:34:58 +1000 Subject: [PATCH 2/2] use fs.access() instead of executable --- index.js | 6 ++++-- package.json | 1 - 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 95637f7..feea5b5 100644 --- a/index.js +++ b/index.js @@ -2,9 +2,10 @@ const {promisify} = require('util'); const path = require('path'); const childProcess = require('child_process'); -const isExe = require('executable'); +const fs = require('fs'); const isWsl = require('is-wsl'); +const pAccess = promisify(fs.access); const pExecFile = promisify(childProcess.execFile); // Path to included `xdg-open` @@ -83,7 +84,8 @@ module.exports = async (target, options) => { // Check if local `xdg-open` exists and is executable. let exeLocalXdgOpen = false; try { - exeLocalXdgOpen = await isExe(localXdgOpenPath); + await pAccess(localXdgOpenPath, fs.constants.X_OK); + exeLocalXdgOpen = true; } catch (error) {} const useSystemXdgOpen = process.versions.electron || diff --git a/package.json b/package.json index f9a7077..8f6fdbe 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,6 @@ "file" ], "dependencies": { - "executable": "^4.1.1", "is-wsl": "^1.1.0" }, "devDependencies": {