Skip to content

Commit

Permalink
Hide private attributes from exports
Browse files Browse the repository at this point in the history
  • Loading branch information
giggio committed Nov 7, 2023
1 parent 379046e commit de961e3
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 20 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ tmp
Dockerfile
*.sh
testInstall.js
testStart.js
update.js
*.tgz
.vscode
Expand Down
40 changes: 25 additions & 15 deletions lib/chromedriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ const path = require('path');
const tcpPortUsed = require('tcp-port-used');
function getPortFromArgs(args) {
let port = 9515;
if (!args) {
if (!args)
return port;
}
const portRegexp = /--port=(\d*)/;
const portArg = args.find(function (arg) {
return portRegexp.test(arg);
});
if (portArg) {
if (portArg)
port = parseInt(portRegexp.exec(portArg)[1]);
}
return port;
}
process.env.PATH = path.join(__dirname, 'chromedriver') + path.delimiter + process.env.PATH;
exports.path = process.platform === 'win32' ? path.join(__dirname, 'chromedriver', 'chromedriver.exe') : path.join(__dirname, 'chromedriver', 'chromedriver');
exports.version = '119.0.6045.105';
exports.start = function (args, returnPromise) {
let command = exports.path;
const crpath = process.platform === 'win32' ? path.join(__dirname, 'chromedriver', 'chromedriver.exe') : path.join(__dirname, 'chromedriver', 'chromedriver');
const version = '119.0.6045.105';
let defaultInstance = null;

function start(args, returnPromise) {
let command = crpath;
if (!fs.existsSync(command)) {
console.log('Could not find chromedriver in default path: ', command);
console.log('Falling back to use global chromedriver bin');
Expand All @@ -28,20 +28,30 @@ exports.start = function (args, returnPromise) {
const cp = require('child_process').spawn(command, args);
cp.stdout.pipe(process.stdout);
cp.stderr.pipe(process.stderr);
exports.defaultInstance = cp;
if (!returnPromise) {
defaultInstance = cp;
if (!returnPromise)
return cp;
}
const port = getPortFromArgs(args);
const pollInterval = 100;
const timeout = 10000;
return tcpPortUsed.waitUntilUsed(port, pollInterval, timeout)
.then(function () {
return cp;
});
};
exports.stop = function () {
if (exports.defaultInstance != null) {
exports.defaultInstance.kill();
}

function stop() {
if (defaultInstance != null)
defaultInstance.kill();
defaultInstance = null;
}

module.exports = {
path: crpath,
version,
start,
stop,
get defaultInstance() {
return defaultInstance;
}
};
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chromedriver",
"version": "119.0.0",
"version": "119.0.1",
"keywords": [
"chromedriver",
"selenium"
Expand Down
14 changes: 14 additions & 0 deletions testStart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env node

"use strict";
const chromedriver = require('./lib/chromedriver');

async function run() {
console.log(`Starting chromedriver. Instance: ${JSON.stringify(chromedriver)}`);
await chromedriver.start(null, true);
console.log(`Started Chromedriver. Instance is null: ${chromedriver.defaultInstance === null}.`);
chromedriver.stop();
console.log(`Stopped Chromedriver. Instance is null: ${chromedriver.defaultInstance === null}.`);
}

run();
4 changes: 2 additions & 2 deletions update.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ async function getLatest() {
}

/* Provided a new Chromedriver version such as 77.0.3865.40:
- update the version inside the ./lib/chromedriver helper file e.g. exports.version = '77.0.3865.40';
- update the version inside the ./lib/chromedriver helper file e.g. const version = '77.0.3865.40';
- bumps package.json version number
- add a git tag using the new node-chromedriver version
- add a git commit, e.g. Bump version to 77.0.0
*/
async function writeUpdate(newVersion, shouldCommit) {
const helper = fs.readFileSync('./lib/chromedriver.js', 'utf8');
const versionExport = 'exports.version';
const versionExport = 'const version';
const regex = new RegExp(`^.*${versionExport}.*$`, 'gm');
const updated = helper.replace(regex, `${versionExport} = '${newVersion}';`);
const currentMajor = semver.major(currentVersionInPackageJson);
Expand Down

0 comments on commit de961e3

Please sign in to comment.