From 4767f41c2cf95ce14559cf34da48a11becbb1a23 Mon Sep 17 00:00:00 2001 From: Paul Hawxby Date: Tue, 25 Apr 2017 15:28:56 +0100 Subject: [PATCH 1/8] Using standard proxy env var --- install.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/install.js b/install.js index c45f04bab..82cfe126e 100644 --- a/install.js +++ b/install.js @@ -153,7 +153,10 @@ function getRequestOptions() { var proxyUrl = process.env.npm_config_https_proxy || process.env.npm_config_http_proxy || - process.env.npm_config_proxy + process.env.npm_config_proxy || + process.env.http_proxy; + + if (proxyUrl) { // Print using proxy From c41e59ada3acd97034be2efd7261d91fb6434499 Mon Sep 17 00:00:00 2001 From: Paul Hawxby Date: Tue, 25 Apr 2017 15:29:11 +0100 Subject: [PATCH 2/8] Adding support for phantomjs 2.5.0 beta --- lib/phantomjs.js | 2 +- lib/util.js | 17 +++++++---------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/phantomjs.js b/lib/phantomjs.js index 6dc10fd20..8c9defa5a 100644 --- a/lib/phantomjs.js +++ b/lib/phantomjs.js @@ -30,7 +30,7 @@ try { * The version of phantomjs installed by this package. * @type {number} */ -exports.version = '2.1.1' +exports.version = '2.5.0' /** diff --git a/lib/util.js b/lib/util.js index 7a3c17d0f..b878843f6 100644 --- a/lib/util.js +++ b/lib/util.js @@ -11,7 +11,7 @@ var helper = require('./phantomjs') var kew = require('kew') var path = require('path') -var DEFAULT_CDN = 'https://github.com/Medium/phantomjs/releases/download/v2.1.1' +var DEFAULT_CDN = 'https://bitbucket.org/ariya/phantomjs/downloads' var libPath = __dirname /** @@ -98,17 +98,14 @@ function getDownloadSpec() { var platform = getTargetPlatform() var arch = getTargetArch() if (platform === 'linux' && arch === 'x64') { - downloadUrl += 'linux-x86_64.tar.bz2' - checksum = '86dd9a4bf4aee45f1a84c9f61cf1947c1d6dce9b9e8d2a907105da7852460d2f' - } else if (platform === 'linux' && arch == 'ia32') { - downloadUrl += 'linux-i686.tar.bz2' - checksum = '80e03cfeb22cc4dfe4e73b68ab81c9fdd7c78968cfd5358e6af33960464f15e3' + downloadUrl += 'beta-linux-ubuntu-trusty-x86_64.tar.gz' + checksum = '00E75A5A359A777DB95E4EDEDD4C5E8755D5852CB016CBCCFCA6F5E2A08C4A09' } else if (platform === 'darwin') { - downloadUrl += 'macosx.zip' - checksum = '538cf488219ab27e309eafc629e2bcee9976990fe90b1ec334f541779150f8c1' + downloadUrl += 'beta-macos.zip' + checksum = '8183EAAAC1BF73EDBE2414870FFA4B6262B42AB97D3F252CEE073746CA272ACC' } else if (platform === 'win32') { - downloadUrl += 'windows.zip' - checksum = 'd9fb05623d6b26d3654d008eab3adafd1f6350433dfd16138c46161f42c7dcc8' + downloadUrl += 'beta-windows.zip' + checksum = '3E0D684E7564862CBF43E38B9E29DD087052DE19D76C525D6F08C37D211A4381' } else { return null } From 00ec3b001224599098905d34d39926f7f1caea9c Mon Sep 17 00:00:00 2001 From: Paul Hawxby Date: Tue, 25 Apr 2017 15:30:35 +0100 Subject: [PATCH 3/8] Updating version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ccd9fadea..cfe9beb34 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "phantomjs-prebuilt", - "version": "2.1.14", + "version": "2.5.0", "keywords": [ "phantomjs", "headless", From c7d44f4c67f0baffd105850b4901f96bfbd2e3ed Mon Sep 17 00:00:00 2001 From: Paul Hawxby Date: Tue, 25 Apr 2017 16:22:17 +0100 Subject: [PATCH 4/8] Better linux handling --- lib/util.js | 51 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/lib/util.js b/lib/util.js index b878843f6..abddfce6f 100644 --- a/lib/util.js +++ b/lib/util.js @@ -10,6 +10,7 @@ var hasha = require('hasha') var helper = require('./phantomjs') var kew = require('kew') var path = require('path') +var os = require('os') var DEFAULT_CDN = 'https://bitbucket.org/ariya/phantomjs/downloads' var libPath = __dirname @@ -88,27 +89,50 @@ function writeLocationFile(location) { * @return {?{url: string, checksum: string}} Get the download URL and expected * SHA-256 checksum for phantomjs. May return null if no download url exists. */ -function getDownloadSpec() { +function getDownloadSpec() +{ var cdnUrl = process.env.npm_config_phantomjs_cdnurl || process.env.PHANTOMJS_CDNURL || DEFAULT_CDN + var downloadUrl = cdnUrl + '/phantomjs-' + helper.version + '-' var checksum = '' var platform = getTargetPlatform() - var arch = getTargetArch() - if (platform === 'linux' && arch === 'x64') { - downloadUrl += 'beta-linux-ubuntu-trusty-x86_64.tar.gz' - checksum = '00E75A5A359A777DB95E4EDEDD4C5E8755D5852CB016CBCCFCA6F5E2A08C4A09' - } else if (platform === 'darwin') { + + if (platform === 'linux') + { + var release = getTargetPlatformRelease(); + + if (release) + { + var releaseMajor = release.split(".")[0]; + + if (releaseMajor == 14) { + downloadUrl += 'beta-linux-ubuntu-trusty-x86_64.tar.gz' + checksum = '00E75A5A359A777DB95E4EDEDD4C5E8755D5852CB016CBCCFCA6F5E2A08C4A09' + } + else if (releaseMajor == 16) { + downloadUrl += 'beta-linux-ubuntu-xenial-x86_64.tar' + checksum = 'B478BB44E7A77468683A615BDA082716D76E99DC17EBBC005D31D06B6715429E' + } + } + else { + return null; + } + } + else if (platform === 'darwin') { downloadUrl += 'beta-macos.zip' checksum = '8183EAAAC1BF73EDBE2414870FFA4B6262B42AB97D3F252CEE073746CA272ACC' - } else if (platform === 'win32') { + } + else if (platform === 'win32') { downloadUrl += 'beta-windows.zip' checksum = '3E0D684E7564862CBF43E38B9E29DD087052DE19D76C525D6F08C37D211A4381' - } else { + } + else { return null } + return {url: downloadUrl, checksum: checksum} } @@ -137,14 +161,21 @@ function verifyChecksum(fileName, checksum) { * @return {string} */ function getTargetPlatform() { - return process.env.PHANTOMJS_PLATFORM || process.platform + return process.env.PHANTOMJS_PLATFORM || os.platform(); +} + +/** + * @return {string} + */ +function getTargetPlatformRelease() { + return process.env.PHANTOMJS_PLATFORM_RELEASE || os.release(); } /** * @return {string} */ function getTargetArch() { - return process.env.PHANTOMJS_ARCH || process.arch + return process.env.PHANTOMJS_ARCH || os.arch(); } module.exports = { From 87c5fbfa032ca32bc3596e6f21772a0d0aeb6102 Mon Sep 17 00:00:00 2001 From: Paul Hawxby Date: Tue, 25 Apr 2017 16:27:11 +0100 Subject: [PATCH 5/8] Improved debugging --- install.js | 2 +- lib/util.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/install.js b/install.js index 82cfe126e..ea7d15d37 100644 --- a/install.js +++ b/install.js @@ -408,7 +408,7 @@ function downloadPhantomjs() { var downloadSpec = getDownloadSpec() if (!downloadSpec) { console.error( - 'Unexpected platform or architecture: ' + getTargetPlatform() + '/' + getTargetArch() + '\n' + + 'Unexpected platform or architecture: ' + getTargetPlatform() + '/' + getTargetArch() + '/' + getTargetPlatformRelease() + '\n' + 'It seems there is no binary available for your platform/architecture\n' + 'Try to install PhantomJS globally') exit(1) diff --git a/lib/util.js b/lib/util.js index abddfce6f..03784f2d6 100644 --- a/lib/util.js +++ b/lib/util.js @@ -115,6 +115,9 @@ function getDownloadSpec() else if (releaseMajor == 16) { downloadUrl += 'beta-linux-ubuntu-xenial-x86_64.tar' checksum = 'B478BB44E7A77468683A615BDA082716D76E99DC17EBBC005D31D06B6715429E' + } + else { + return null; } } else { From 3f4d602d77b0160d3ae2ac0cd79abce5d4aba55a Mon Sep 17 00:00:00 2001 From: Paul Hawxby Date: Tue, 25 Apr 2017 16:31:25 +0100 Subject: [PATCH 6/8] Forgot to export --- install.js | 1 + lib/util.js | 1 + 2 files changed, 2 insertions(+) diff --git a/install.js b/install.js index ea7d15d37..e5d73174f 100644 --- a/install.js +++ b/install.js @@ -24,6 +24,7 @@ var originalPath = process.env.PATH var checkPhantomjsVersion = util.checkPhantomjsVersion var getTargetPlatform = util.getTargetPlatform +var getTargetPlatformRelease = util.getTargetPlatformRelease var getTargetArch = util.getTargetArch var getDownloadSpec = util.getDownloadSpec var findValidPhantomJsBinary = util.findValidPhantomJsBinary diff --git a/lib/util.js b/lib/util.js index 03784f2d6..8cda15120 100644 --- a/lib/util.js +++ b/lib/util.js @@ -185,6 +185,7 @@ module.exports = { checkPhantomjsVersion: checkPhantomjsVersion, getDownloadSpec: getDownloadSpec, getTargetPlatform: getTargetPlatform, + getTargetPlatformRelease: getTargetPlatformRelease, getTargetArch: getTargetArch, findValidPhantomJsBinary: findValidPhantomJsBinary, verifyChecksum: verifyChecksum, From 11198ab5b4c9c65614539159e1c912c7d28cc586 Mon Sep 17 00:00:00 2001 From: Paul Hawxby Date: Tue, 25 Apr 2017 17:58:16 +0100 Subject: [PATCH 7/8] Pulling release version from lsb --- lib/util.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/util.js b/lib/util.js index 8cda15120..a57d2c1b0 100644 --- a/lib/util.js +++ b/lib/util.js @@ -98,7 +98,7 @@ function getDownloadSpec() var downloadUrl = cdnUrl + '/phantomjs-' + helper.version + '-' var checksum = '' - var platform = getTargetPlatform() + var platform = getTargetPlatform(); if (platform === 'linux') { @@ -171,6 +171,20 @@ function getTargetPlatform() { * @return {string} */ function getTargetPlatformRelease() { + + var platform = getTargetPlatform(); + + if (platform === 'linux') + { + let child = cp.spawnSync( 'lsb_release', ['-a'] ); + let lsb_release = child.stdout.toString(); + + var match = lsb_release.match(/(?:Release:\s+)([0-9\.]+)/); + if (match) { + return match[1]; + } + } + return process.env.PHANTOMJS_PLATFORM_RELEASE || os.release(); } From 20013c42c41b95ef8088e1e783a205274877580e Mon Sep 17 00:00:00 2001 From: Paul Hawxby Date: Tue, 25 Apr 2017 18:20:49 +0100 Subject: [PATCH 8/8] Switching to decompress as it suppot tar.gz --- install.js | 33 ++++++++++----------------------- lib/util.js | 6 ++++-- package.json | 2 +- 3 files changed, 15 insertions(+), 26 deletions(-) diff --git a/install.js b/install.js index e5d73174f..10e599b71 100644 --- a/install.js +++ b/install.js @@ -8,7 +8,7 @@ var requestProgress = require('request-progress') var progress = require('progress') -var extractZip = require('extract-zip') +var decompress = require('decompress') var cp = require('child_process') var fs = require('fs-extra') var helper = require('./lib/phantomjs') @@ -270,35 +270,22 @@ function extractDownload(filePath) { // extract to a unique directory in case multiple processes are // installing and extracting at once var extractedPath = filePath + '-extract-' + Date.now() - var options = {cwd: extractedPath} fs.mkdirsSync(extractedPath, '0777') // Make double sure we have 0777 permissions; some operating systems // default umask does not allow write by default. fs.chmodSync(extractedPath, '0777') - if (filePath.substr(-4) === '.zip') { - console.log('Extracting zip contents') - extractZip(path.resolve(filePath), {dir: extractedPath}, function(err) { - if (err) { - console.error('Error extracting zip') - deferred.reject(err) - } else { - deferred.resolve(extractedPath) - } - }) + console.log('Extracting archive') + decompress(path.resolve(filePath), extractedPath) + .then(function(files) { + deferred.resolve(extractedPath) + }, + function(err) { + console.error('Error extracting zip') + deferred.reject(err) + }); - } else { - console.log('Extracting tar contents (via spawned process)') - cp.execFile('tar', ['jxf', path.resolve(filePath)], options, function (err) { - if (err) { - console.error('Error extracting archive') - deferred.reject(err) - } else { - deferred.resolve(extractedPath) - } - }) - } return deferred.promise } diff --git a/lib/util.js b/lib/util.js index a57d2c1b0..d817842b9 100644 --- a/lib/util.js +++ b/lib/util.js @@ -72,14 +72,16 @@ function writeLocationFile(location) { } var platform = getTargetPlatform() + var release = getTargetPlatformRelease() var arch = getTargetArch() var contents = 'module.exports.location = "' + location + '"\n' if (/^[a-zA-Z0-9]*$/.test(platform) && /^[a-zA-Z0-9]*$/.test(arch)) { contents += - 'module.exports.platform = "' + getTargetPlatform() + '"\n' + - 'module.exports.arch = "' + getTargetArch() + '"\n' + 'module.exports.platform = "' + platform + '"\n' + + 'module.exports.platformRelease = "' + release + '"\n' + + 'module.exports.arch = "' + arch + '"\n' } fs.writeFileSync(path.join(libPath, 'location.js'), contents) diff --git a/package.json b/package.json index cfe9beb34..85dd04040 100644 --- a/package.json +++ b/package.json @@ -39,8 +39,8 @@ "test": "nodeunit --reporter=minimal test/tests.js && eslint ." }, "dependencies": { + "decompress": "^4.1.0", "es6-promise": "~4.0.3", - "extract-zip": "~1.5.0", "fs-extra": "~1.0.0", "hasha": "~2.2.0", "kew": "~0.7.0",