diff --git a/index.js b/index.js index 74c08a3..e457c7e 100644 --- a/index.js +++ b/index.js @@ -8,7 +8,7 @@ const defineLazyProperty = require('define-lazy-prop'); // Path to included `xdg-open`. const localXdgOpenPath = path.join(__dirname, 'xdg-open'); -const {platform} = process; +const {platform, arch} = process; /** Get the mount point for fixed drives in WSL. @@ -215,33 +215,50 @@ const open = async (target, options) => { return subprocess; }; -function detectPlatformBinary(platformMap, {wsl}) { +function detectArchBinary(binary) { + if (typeof binary === 'string') { + return binary; + } + + const {[arch]: archBinary} = binary; + + if (!archBinary) { + throw new Error(`${arch} is not supported`); + } + + return archBinary; +} + +function detectPlatformBinary({[platform]: platformBinary}, {wsl}) { if (wsl && isWsl) { - return wsl; + return detectArchBinary(wsl); } - if (!platformMap.has(platform)) { + if (!platformBinary) { throw new Error(`${platform} is not supported`); } - return platformMap.get(platform); + return detectArchBinary(platformBinary); } const apps = {}; -defineLazyProperty(apps, 'chrome', () => detectPlatformBinary(new Map([ - ['darwin', 'google chrome canary'], - ['win32', 'Chrome'], - ['linux', ['google-chrome', 'google-chrome-stable']] -]), { - wsl: '/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe' +defineLazyProperty(apps, 'chrome', () => detectPlatformBinary({ + darwin: 'google chrome canary', + win32: 'chrome', + linux: ['google-chrome', 'google-chrome-stable'] +}, { + wsl: { + ia32: '/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe', + x64: ['/mnt/c/Program Files/Google/Chrome/Application/chrome.exe', '/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe'] + } })); -defineLazyProperty(apps, 'firefox', () => detectPlatformBinary(new Map([ - ['darwin', 'firefox'], - ['win32', 'C:\\Program Files\\Mozilla Firefox\\firefox.exe'], - ['linux', 'firefox'] -]), { +defineLazyProperty(apps, 'firefox', () => detectPlatformBinary({ + darwin: 'firefox', + win32: 'C:\\Program Files\\Mozilla Firefox\\firefox.exe', + linux: 'firefox' +}, { wsl: '/mnt/c/Program Files/Mozilla Firefox/firefox.exe' })); diff --git a/package.json b/package.json index 3a463c5..065ff9e 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "url": "https://sindresorhus.com" }, "engines": { - "node": "^10.17" + "node": ">=10.17" }, "scripts": { "test": "xo && tsd" @@ -57,5 +57,15 @@ "ava": "^3.15.0", "tsd": "^0.14.0", "xo": "^0.37.1" + }, + "xo": { + "rules": { + "node/no-unsupported-features/node-builtins": [ + "error", + { + "ignores": ["fs.promises"] + } + ] + } } }