Skip to content

Commit

Permalink
tslint -> eslint (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmlemeshko authored Feb 3, 2021
1 parent 6995863 commit 0e3f8fe
Show file tree
Hide file tree
Showing 9 changed files with 636 additions and 109 deletions.
16 changes: 16 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
parser: '@typescript-eslint/parser', // Specifies the ESLint parser
parserOptions: {
ecmaVersion: 2020, // Allows for the parsing of modern ECMAScript features
sourceType: 'module', // Allows for the use of imports
},
extends: [
'plugin:@typescript-eslint/recommended', // Uses the recommended rules from the @typescript-eslint/eslint-plugin
'prettier/@typescript-eslint', // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
'plugin:prettier/recommended', // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
],
rules: {
// Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs
// e.g. "@typescript-eslint/explicit-function-return-type": "off",
},
};
7 changes: 7 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
semi: true,
trailingComma: "all",
singleQuote: true,
printWidth: 120,
tabWidth: 4
};
37 changes: 22 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,36 @@
"buildWin": "del /s/q lib bin msedgedriver.zip paths.json & tsc -p .",
"prepare": "npm run build",
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
"lint": "tslint -p tsconfig.json",
"lint": "eslint -c .eslintrc.js --ext .ts src",
"precommit-msg": "echo 'Pre-commit checks...' && exit 0"
},
"pre-commit": ["precommit-msg", "lint"],
"pre-commit": [
"precommit-msg",
"lint"
],
"dependencies": {
"extract-zip": "^2.0.0",
"got": "^11.6.0",
"lodash": "^4.17.15",
"extract-zip": "^2.0.1",
"got": "^11.8.1",
"lodash": "^4.17.20",
"regedit": "^3.0.3",
"util": "^0.12.2"
"util": "^0.12.3"
},
"devDependencies": {
"@types/extract-zip": "^1.6.2",
"@types/got": "^9.6.9",
"@types/jest": "^26.0.10",
"@types/lodash": "^4.14.161",
"@types/node": "^14.6.4",
"jest": "^26.4.2",
"@types/got": "^9.6.11",
"@types/jest": "^26.0.20",
"@types/lodash": "^4.14.168",
"@types/node": "^14.14.22",
"@typescript-eslint/eslint-plugin": "^4.14.2",
"@typescript-eslint/parser": "^4.14.2",
"eslint": "^7.19.0",
"eslint-config-prettier": "^7.2.0",
"eslint-plugin-prettier": "^3.3.1",
"jest": "^26.6.3",
"jest-mock-process": "^1.4.0",
"pre-commit": "^1.2.2",
"ts-jest": "^26.2.0",
"tslint": "^6.1.1",
"tslint-config-prettier": "^1.18.0",
"typescript": "^4.0.2"
"prettier": "^2.2.1",
"ts-jest": "^26.5.0",
"typescript": "^4.1.3"
}
}
20 changes: 14 additions & 6 deletions src/browser.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { exec } from 'child_process';
import { promisify } from 'util';
import { join } from 'path';
import * as _ from 'lodash';
import { isWin } from './os';
const execAsync = promisify(exec);
const DEFAULT_EDGE_BINARY_PATH = '/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge';
const DEFAULT_EDGE_HKEY =
'HKLM\\SOFTWARE\\WOW6432Node\\Microsoft\\EdgeUpdate\\Clients\\{56EB18F8-B008-4CBD-B6D2-8C97FE7E9062}';

const getRegistryKey = async (key: string) => {
type RegistryKey = { values: { location: { value: string }; pv: { value: string } } };

const getRegistryKey = async (key: string): Promise<RegistryKey> => {
return new Promise((resolve, reject) => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const regedit = require('regedit');
regedit.list(key, (err: any, result: any) => {
regedit.list(key as string, (err: NodeJS.ErrnoException | null, result: { [key: string]: RegistryKey }) => {
if (err) {
return reject(err);
} else {
Expand All @@ -26,9 +28,7 @@ const getBrowserBinaryOnWin = async () => {
const edgeBinaryHKey = process.env.EDGE_HKEY || DEFAULT_EDGE_HKEY;
try {
const key = await getRegistryKey(edgeBinaryHKey);
// @ts-ignore
const path = key.values.location.value;
// @ts-ignore
const version = key.values.pv.value;
return { path: join(path, fileName), version };
} catch (err) {
Expand All @@ -50,6 +50,14 @@ const getBrowserBinaryOnMac = async (edgeBinaryPath?: string | undefined) => {
}
};

export const getBrowserData = async (edgeBinaryPath?: string | undefined) => {
export const getBrowserData = async (
edgeBinaryPath?: string | undefined,
): Promise<
| {
path: string;
version: string;
}
| undefined
> => {
return await (isWin() ? getBrowserBinaryOnWin() : getBrowserBinaryOnMac(edgeBinaryPath));
};
2 changes: 1 addition & 1 deletion src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe('Setting explicitly browser and driver path', () => {
describe('Downloading driver', () => {
let mockStdout: jest.SpyInstance;
const majorVersion = '85';
const fullVersion = '85.0.564.63'
const fullVersion = '85.0.564.63';

beforeEach(() => {
cleanup();
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const edgePathFile = 'paths.json';

const pipelineAsync = promisify(pipeline);

const isStringHasValue = (value: any) => {
const isStringHasValue = (value: string | undefined) => {
return _.isString(value) && value.length > 0;
};

Expand Down Expand Up @@ -111,7 +111,7 @@ const findDriverInPath = () => {
return Fs.existsSync(driverPath) ? driverPath : null;
};

export const installDriver = async () => {
export const installDriver = async (): Promise<{ browserPath: string; driverPath: string }> => {
const edgeBinaryPath = process.env.npm_config_edge_binary_path || process.env.EDGE_BINARY_PATH;
const edgeDriverPath = process.env.npm_config_edgedriver_path || process.env.EDGEDRIVER_PATH;
if (edgeBinaryPath && edgeDriverPath && isStringHasValue(edgeBinaryPath) && isStringHasValue(edgeDriverPath)) {
Expand All @@ -137,7 +137,7 @@ export const installDriver = async () => {
}
};

export const paths = () => {
export const paths = (): { browserPath: string | undefined; driverPath: string | undefined } => {
if (Fs.existsSync(edgePathFile)) {
const rawdata = Fs.readFileSync(edgePathFile);
return JSON.parse(rawdata.toString()) as { browserPath: string; driverPath: string };
Expand Down
2 changes: 1 addition & 1 deletion src/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const downloadOnInstall =
if (downloadOnInstall) {
installDriver().then((paths) => {
process.stdout.write(`MS Edge driver is set: ${JSON.stringify(paths)}\n`);
Fs.writeFile(edgePathFile, JSON.stringify(paths), (err: any) => {
Fs.writeFile(edgePathFile, JSON.stringify(paths), (err) => {
if (err) return process.stdout.write(`${err}\n`);
});
});
Expand Down
3 changes: 0 additions & 3 deletions tslint.json

This file was deleted.

Loading

0 comments on commit 0e3f8fe

Please sign in to comment.