Skip to content

Commit

Permalink
Allow a file on the filesystem to be used as the source
Browse files Browse the repository at this point in the history
  • Loading branch information
groothuyse authored and giggio committed Jan 11, 2017
1 parent 33e922d commit a66d829
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
20 changes: 20 additions & 0 deletions README.md
Expand Up @@ -47,6 +47,26 @@ Another option is to use PATH variable `CHROMEDRIVER_CDNURL`.
CHROMEDRIVER_CDNURL=http://npm.taobao.org/mirrors/chromedriver npm install chromedriver
```

### Custom binaries file

To get the chromedriver from the filesystem instead of a web request use the npm config property `chromedriver_filepath`.

```shell
npm install chromedriver --chromedriver_filepath=/path/to/chromedriver_mac64.zip
```

Or add property into your [`.npmrc`](https://docs.npmjs.com/files/npmrc) file.

```
chromedriver_filepath=/path/to/chromedriver_mac64.zip
```

Another option is to use the PATH variable `CHROMEDRIVER_FILEPATH`

```shell
CHROMEDRIVER_FILEPATH=/path/to/chromedriver_mac64.zip
```

Running
-------

Expand Down
21 changes: 14 additions & 7 deletions install.js
Expand Up @@ -14,6 +14,8 @@ var util = require('util');

var libPath = path.join(__dirname, 'lib', 'chromedriver');
var cdnUrl = process.env.npm_config_chromedriver_cdnurl || process.env.CHROMEDRIVER_CDNURL || 'https://chromedriver.storage.googleapis.com';
var configuredfilePath = process.env.npm_config_chromedriver_filepath || process.env.CHROMEDRIVER_FILEPATH;

// adapt http://chromedriver.storage.googleapis.com/
cdnUrl = cdnUrl.replace(/\/+$/, '');
var downloadUrl = cdnUrl + '/%s/chromedriver_%s.zip';
Expand Down Expand Up @@ -55,12 +57,17 @@ promise = promise.then(function () {

// Start the install.
promise = promise.then(function () {
downloadUrl = util.format(downloadUrl, chromedriver_version, platform);
var fileName = downloadUrl.split('/').pop();
downloadedFile = path.join(tmpPath, fileName);
console.log('Downloading', downloadUrl);
console.log('Saving to', downloadedFile);
return requestBinary(getRequestOptions(downloadUrl), downloadedFile);
if (configuredfilePath) {
console.log('Using file: ', configuredfilePath);
downloadedFile = configuredfilePath;
} else {
downloadUrl = util.format(downloadUrl, chromedriver_version, platform);
var fileName = downloadUrl.split('/').pop();
downloadedFile = path.join(tmpPath, fileName);
console.log('Downloading', downloadUrl);
console.log('Saving to', downloadedFile);
return requestBinary(getRequestOptions(downloadUrl), downloadedFile);
}
});

promise.then(function () {
Expand Down Expand Up @@ -274,4 +281,4 @@ function fixFilePermissions() {
fs.chmodSync(helper.path, '755');
}
}
}
}

0 comments on commit a66d829

Please sign in to comment.