Skip to content

Commit

Permalink
chore: replacte eslint with xojs
Browse files Browse the repository at this point in the history
Also upgrade babel
  • Loading branch information
michaellzc committed Apr 6, 2020
1 parent 1590a53 commit fca0880
Show file tree
Hide file tree
Showing 4 changed files with 3,424 additions and 750 deletions.
6 changes: 0 additions & 6 deletions .eslintrc.json

This file was deleted.

22 changes: 13 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,25 @@
"README.md",
"yarn.lock"
],
"xo": {
"_nodeVersion": "falling back to --node-version cli argument since this is not working",
"nodeVersion": ">=10.0.0",
"space": 2,
"prettier": true,
"envs": ["node"]
},
"scripts": {
"build": "babel src -d dist",
"lint": "eslint src --fix",
"format": "prettier --write \"src/**/*.js\""
"_lint": "--node-version is a work around since we use v8 as target in babel anyway",
"lint": "xo src/ --fix --node-version \">=10.0.0\""
},
"dependencies": {
"open": "^7.0.3"
},
"devDependencies": {
"@babel/cli": "^7.2.0",
"@babel/core": "^7.2.0",
"@babel/preset-env": "^7.2.0",
"eslint": "^5.10.0",
"eslint-config-prettier": "^3.3.0",
"eslint-plugin-prettier": "^3.0.0",
"prettier": "^1.13.7"
"@babel/cli": "^7.8.4",
"@babel/core": "^7.9.0",
"@babel/preset-env": "^7.9.0",
"xo": "^0.28.3"
}
}
37 changes: 22 additions & 15 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { execSync } = require('child_process');
const {execSync} = require('child_process');

const OSX_CHROME = 'google chrome';

Expand All @@ -13,9 +13,9 @@ const getBrowserEnv = () => {
// See https://github.com/sindresorhus/open#app for documentation.
const value = process.env.BROWSER;
const args = process.env.BROWSER_ARGS
? process.env.BROWSER_ARGS.split(' ')
: [];
let action
? process.env.BROWSER_ARGS.split(' ')
: [];
let action;
if (!value) {
// Default.
action = Actions.BROWSER;
Expand All @@ -25,11 +25,12 @@ const getBrowserEnv = () => {
action = Actions.BROWSER;
}

return { action, value, args };
return {action, value, args};
};

// Copy from
// https://github.com/facebook/create-react-app/blob/master/packages/react-dev-utils/openBrowser.js#L64
// eslint-disable-next-line unicorn/prevent-abbreviations
const startBrowserProcess = (browser, url, opts = {}, args = []) => {
// If we're on OS X, the user hasn't specifically
// requested a different browser, we can try opening
Expand All @@ -49,18 +50,24 @@ const startBrowserProcess = (browser, url, opts = {}, args = []) => {
'Vivaldi',
'Chromium',
];
for (let chromiumBrowser of supportedChromiumBrowsers) {
for (const chromiumBrowser of supportedChromiumBrowsers) {
try {
// Try our best to reuse existing tab
// on OSX Chromium-based browser with AppleScript
execSync('ps cax | grep "' + chromiumBrowser + '"');
execSync(`osascript ../openChrome.applescript "${encodeURI(url)}" "${chromiumBrowser}"`, {
cwd: __dirname,
stdio: 'ignore',
});
execSync(
`osascript ../openChrome.applescript "${encodeURI(
url
)}" "${chromiumBrowser}"`,
{
cwd: __dirname,
stdio: 'ignore',
}
);

return Promise.resolve(true);
} catch (err) {
// eslint-disable-next-line no-unused-vars
} catch (error) {
// Ignore errors.
// It it breaks, it will fallback to `opn` anyway
}
Expand All @@ -82,18 +89,18 @@ const startBrowserProcess = (browser, url, opts = {}, args = []) => {

// Fallback to opn
// (It will always open new tab)
const options = { app: browser, url: true, wait: false, ...opts };
const options = {app: browser, url: true, wait: false, ...opts};
return require('open')(url, options);
};

module.exports = (target, opts) => {
const { action, value, args } = getBrowserEnv();
module.exports = (target, options) => {
const {action, value, args} = getBrowserEnv();
switch (action) {
case Actions.NONE:
// Special case: BROWSER="none" will prevent opening completely.
return false;
case Actions.BROWSER:
return startBrowserProcess(value, target, opts, args);
return startBrowserProcess(value, target, options, args);
default:
throw new Error('Not implemented.');
}
Expand Down
Loading

0 comments on commit fca0880

Please sign in to comment.