Skip to content

Commit de961e3

Browse files
committed
Hide private attributes from exports
1 parent 379046e commit de961e3

6 files changed

+45
-20
lines changed

.npmignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ tmp
55
Dockerfile
66
*.sh
77
testInstall.js
8+
testStart.js
89
update.js
910
*.tgz
1011
.vscode

lib/chromedriver.js

+25-15
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@ const path = require('path');
33
const tcpPortUsed = require('tcp-port-used');
44
function getPortFromArgs(args) {
55
let port = 9515;
6-
if (!args) {
6+
if (!args)
77
return port;
8-
}
98
const portRegexp = /--port=(\d*)/;
109
const portArg = args.find(function (arg) {
1110
return portRegexp.test(arg);
1211
});
13-
if (portArg) {
12+
if (portArg)
1413
port = parseInt(portRegexp.exec(portArg)[1]);
15-
}
1614
return port;
1715
}
1816
process.env.PATH = path.join(__dirname, 'chromedriver') + path.delimiter + process.env.PATH;
19-
exports.path = process.platform === 'win32' ? path.join(__dirname, 'chromedriver', 'chromedriver.exe') : path.join(__dirname, 'chromedriver', 'chromedriver');
20-
exports.version = '119.0.6045.105';
21-
exports.start = function (args, returnPromise) {
22-
let command = exports.path;
17+
const crpath = process.platform === 'win32' ? path.join(__dirname, 'chromedriver', 'chromedriver.exe') : path.join(__dirname, 'chromedriver', 'chromedriver');
18+
const version = '119.0.6045.105';
19+
let defaultInstance = null;
20+
21+
function start(args, returnPromise) {
22+
let command = crpath;
2323
if (!fs.existsSync(command)) {
2424
console.log('Could not find chromedriver in default path: ', command);
2525
console.log('Falling back to use global chromedriver bin');
@@ -28,20 +28,30 @@ exports.start = function (args, returnPromise) {
2828
const cp = require('child_process').spawn(command, args);
2929
cp.stdout.pipe(process.stdout);
3030
cp.stderr.pipe(process.stderr);
31-
exports.defaultInstance = cp;
32-
if (!returnPromise) {
31+
defaultInstance = cp;
32+
if (!returnPromise)
3333
return cp;
34-
}
3534
const port = getPortFromArgs(args);
3635
const pollInterval = 100;
3736
const timeout = 10000;
3837
return tcpPortUsed.waitUntilUsed(port, pollInterval, timeout)
3938
.then(function () {
4039
return cp;
4140
});
42-
};
43-
exports.stop = function () {
44-
if (exports.defaultInstance != null) {
45-
exports.defaultInstance.kill();
41+
}
42+
43+
function stop() {
44+
if (defaultInstance != null)
45+
defaultInstance.kill();
46+
defaultInstance = null;
47+
}
48+
49+
module.exports = {
50+
path: crpath,
51+
version,
52+
start,
53+
stop,
54+
get defaultInstance() {
55+
return defaultInstance;
4656
}
4757
};

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "chromedriver",
3-
"version": "119.0.0",
3+
"version": "119.0.1",
44
"keywords": [
55
"chromedriver",
66
"selenium"

testStart.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env node
2+
3+
"use strict";
4+
const chromedriver = require('./lib/chromedriver');
5+
6+
async function run() {
7+
console.log(`Starting chromedriver. Instance: ${JSON.stringify(chromedriver)}`);
8+
await chromedriver.start(null, true);
9+
console.log(`Started Chromedriver. Instance is null: ${chromedriver.defaultInstance === null}.`);
10+
chromedriver.stop();
11+
console.log(`Stopped Chromedriver. Instance is null: ${chromedriver.defaultInstance === null}.`);
12+
}
13+
14+
run();

update.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ async function getLatest() {
2121
}
2222

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

0 commit comments

Comments
 (0)