Skip to content

Commit

Permalink
Add support for Windows Subsystem for Linux (#50)
Browse files Browse the repository at this point in the history
* Add support for Windows Subsystem for Linux

* Use is-wsl module
  • Loading branch information
remixz authored and sindresorhus committed Apr 30, 2017
1 parent b792b3b commit fce7021
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
const path = require('path');
const childProcess = require('child_process');
const isWsl = require('is-wsl');

module.exports = (target, opts) => {
if (typeof target !== 'string') {
Expand Down Expand Up @@ -29,8 +30,8 @@ module.exports = (target, opts) => {
if (opts.app) {
args.push('-a', opts.app);
}
} else if (process.platform === 'win32') {
cmd = 'cmd';
} else if (process.platform === 'win32' || isWsl) {
cmd = 'cmd' + (isWsl ? '.exe' : '');
args.push('/c', 'start', '""');
target = target.replace(/&/g, '^&');

Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,8 @@
},
"xo": {
"esnext": true
},
"dependencies": {
"is-wsl": "^1.1.0"
}
}
13 changes: 9 additions & 4 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import test from 'ava';
import isWsl from 'is-wsl';
import m from './';

let chromeName;
let firefoxName;

if (process.platform === 'darwin') {
chromeName = 'google chrome canary';
firefoxName = 'firefox';
} else if (process.platform === 'win32' || isWsl) {
chromeName = 'Chrome';
firefoxName = 'C:\\Program Files\\Mozilla Firefox\\firefox.exe';
} else if (process.platform === 'linux') {
chromeName = 'google-chrome';
} else if (process.platform === 'win32') {
chromeName = 'Chrome';
firefoxName = 'firefox';
}

// tests only checks that opening doesn't return an error
// Tests only checks that opening doesn't return an error
// it has no way make sure that it actually opened anything

// these have to be manually verified
Expand All @@ -29,7 +34,7 @@ test('open url in default app', async () => {
});

test('open url in specified app', async () => {
await m('http://sindresorhus.com', {app: 'firefox'});
await m('http://sindresorhus.com', {app: firefoxName});
});

test('open url in specified app with arguments', async () => {
Expand Down

0 comments on commit fce7021

Please sign in to comment.