Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions .eslintrc.json

This file was deleted.

21 changes: 10 additions & 11 deletions check-latest.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-console */
'use strict';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const pkg = require('./package.json');

const LATEST_URL =
Expand All @@ -17,28 +17,27 @@ function compareVersions(a, b) {
return 0;
}

async function main() {
try {
const response = await fetch(LATEST_URL, {
headers: { Accept: 'application/vnd.github+json' }
});
if (!response.ok) {
throw new Error(`HTTP ${response.status} ${response.statusText}`);
}
const data = await response.json();
const tag = data && data.tag_name;
const tag = data?.tag_name;
if (!tag) {
throw new Error('Could not find tag_name in GitHub release response');
}
const latestVersion = tag.replace(/^v/, '');
const currentVersion = pkg.geckodriver_version;
if (compareVersions(latestVersion, currentVersion) > 0) {
console.log(`Upgrade to ${latestVersion}`);
process.exit(1);
process.exitCode = 1;
} else {
console.log(`Relax, ${currentVersion} is the latest version`);
}
console.log(`Relax, ${currentVersion} is the latest version`);
} catch (error) {
console.log(`Failed to parse latest release version: ${error.message}`);
process.exitCode = 1;
}

main().catch(err => {
console.log(`Failed to parse latest release version: ${err.message}`);
process.exit(1);
});
48 changes: 48 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import prettier from 'eslint-plugin-prettier';
import unicorn from 'eslint-plugin-unicorn';
import globals from 'globals';
import js from '@eslint/js';

export default [
{
ignores: ['vendor/*', 'node_modules/*']
},
js.configs.recommended,
unicorn.configs.recommended,
{
plugins: {
prettier
},

languageOptions: {
globals: {
...globals.node
},

ecmaVersion: 'latest',
sourceType: 'module'
},

rules: {
'prettier/prettier': [
'error',
{
singleQuote: true,
trailingComma: 'none',
arrowParens: 'avoid',
embeddedLanguageFormatting: 'off'
}
],

'require-atomic-updates': 0,
'no-extra-semi': 0,
'no-mixed-spaces-and-tabs': 0,
'unicorn/filename-case': 0,
'unicorn/prevent-abbreviations': 0,
'unicorn/no-array-reduce': 0,
'unicorn/no-array-sort': 0,
'unicorn/no-array-reverse': 0,
'unicorn/prefer-spread': 0
}
}
];
56 changes: 30 additions & 26 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
'use strict';
import os from 'node:os';
import path from 'node:path';
import { execSync } from 'node:child_process';
import { fileURLToPath } from 'node:url';
import { createRequire } from 'node:module';

const os = require('os');
const path = require('path');
const pkg = require('./package');
const { execSync } = require('child_process');
const require = createRequire(import.meta.url);
const pkg = require('./package.json');
const __dirname = path.dirname(fileURLToPath(import.meta.url));

module.exports = {
version: pkg.geckodriver_version,
binPath: function() {
let driverPath = path.resolve(__dirname, 'vendor', 'geckodriver');
if (os.platform() === 'win32') {
return driverPath + '.exe';
} else if (
(os.platform() === 'linux' && os.arch() === 'arm') ||
(os.platform() === 'linux' && os.arch() === 'arm64')
) {
// Special handling for making it easy on Raspberry Pis
try {
const potentialGeckodriverPath = execSync('which geckodriver');
if (potentialGeckodriverPath !== undefined) {
return potentialGeckodriverPath.toString().trim();
}
} catch (e) {
// Catch running inside of Docker on ARM
return driverPath;
export const version = pkg.geckodriver_version;

export function binPath() {
const driverPath = path.resolve(__dirname, 'vendor', 'geckodriver');
if (os.platform() === 'win32') {
return driverPath + '.exe';
}
if (
os.platform() === 'linux' &&
(os.arch() === 'arm' || os.arch() === 'arm64')
) {
// Special handling for making it easy on Raspberry Pis
try {
const potentialGeckodriverPath = execSync('which geckodriver');
if (potentialGeckodriverPath !== undefined) {
return potentialGeckodriverPath.toString().trim();
}
} else {
} catch {
// Catch running inside of Docker on ARM
return driverPath;
}
}
};
return driverPath;
}

export default { version, binPath };
52 changes: 28 additions & 24 deletions install.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
'use strict';

const os = require('node:os');
const path = require('node:path');
const { mkdir, unlink, chmod } = require('node:fs/promises');
const { createWriteStream } = require('node:fs');
const { pipeline } = require('node:stream/promises');
const { Readable } = require('node:stream');
const StreamZip = require('node-stream-zip');
const tar = require('tar');
import os from 'node:os';
import path from 'node:path';
import { mkdir, unlink, chmod } from 'node:fs/promises';
import { createWriteStream } from 'node:fs';
import { pipeline } from 'node:stream/promises';
import { Readable } from 'node:stream';
import { fileURLToPath } from 'node:url';
import { createRequire } from 'node:module';
import StreamZip from 'node-stream-zip';
import tar from 'tar';

const require = createRequire(import.meta.url);
const pkg = require('./package.json');
const __dirname = path.dirname(fileURLToPath(import.meta.url));

// The version of the driver that will be installed
const GECKODRIVER_VERSION = process.env.GECKODRIVER_VERSION
Expand Down Expand Up @@ -55,8 +58,9 @@ function getDriverUrl() {
const arch = os.arch() === 'x64' ? 'win64' : 'win32';
return `${urlBase}geckodriver-${GECKODRIVER_VERSION}-${arch}.zip`;
}
default:
return undefined;
default: {
return;
}
}
}

Expand Down Expand Up @@ -86,7 +90,7 @@ async function downloadFile(url, destination) {
async function extractZip(zipPath, destDir) {
const zip = new StreamZip.async({ file: zipPath });
try {
await zip.extract(null, destDir);
await zip.extract(undefined, destDir);
} finally {
await zip.close();
}
Expand All @@ -95,8 +99,8 @@ async function extractZip(zipPath, destDir) {
async function tryUnlink(p) {
try {
await unlink(p);
} catch (err) {
if (err.code !== 'ENOENT') throw err;
} catch (error) {
if (error.code !== 'ENOENT') throw error;
}
}

Expand Down Expand Up @@ -132,20 +136,20 @@ async function install() {
console.log(`Downloading Geckodriver ${GECKODRIVER_VERSION} from ${url}`);
await downloadFile(url, archivePath);

if (isWindows) {
await extractZip(archivePath, vendorDir);
} else {
await tar.x({ file: archivePath, cwd: vendorDir });
}
await (isWindows
? extractZip(archivePath, vendorDir)
: tar.x({ file: archivePath, cwd: vendorDir }));

await unlink(archivePath);
await chmod(binPath, 0o755);
console.log(`Geckodriver ${GECKODRIVER_VERSION} installed in ${vendorDir}`);
}

install().catch(err => {
try {
await install();
} catch (error) {
console.error(
`Geckodriver ${GECKODRIVER_VERSION} could not be installed: ${err.message}`
`Geckodriver ${GECKODRIVER_VERSION} could not be installed: ${error.message}`
);
process.exit(1);
});
process.exitCode = 1;
}
Loading
Loading