diff --git a/install.js b/install.js index c45f04bab..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') @@ -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 @@ -153,7 +154,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 @@ -266,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 } @@ -405,7 +396,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/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..d817842b9 100644 --- a/lib/util.js +++ b/lib/util.js @@ -10,8 +10,9 @@ var hasha = require('hasha') var helper = require('./phantomjs') var kew = require('kew') var path = require('path') +var os = require('os') -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 /** @@ -71,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) @@ -88,30 +91,53 @@ 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 += 'linux-x86_64.tar.bz2' - checksum = '86dd9a4bf4aee45f1a84c9f61cf1947c1d6dce9b9e8d2a907105da7852460d2f' - } else if (platform === 'linux' && arch == 'ia32') { - downloadUrl += 'linux-i686.tar.bz2' - checksum = '80e03cfeb22cc4dfe4e73b68ab81c9fdd7c78968cfd5358e6af33960464f15e3' - } else if (platform === 'darwin') { - downloadUrl += 'macosx.zip' - checksum = '538cf488219ab27e309eafc629e2bcee9976990fe90b1ec334f541779150f8c1' - } else if (platform === 'win32') { - downloadUrl += 'windows.zip' - checksum = 'd9fb05623d6b26d3654d008eab3adafd1f6350433dfd16138c46161f42c7dcc8' - } else { + var platform = getTargetPlatform(); + + 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 { + return null; + } + } + else if (platform === 'darwin') { + downloadUrl += 'beta-macos.zip' + checksum = '8183EAAAC1BF73EDBE2414870FFA4B6262B42AB97D3F252CEE073746CA272ACC' + } + else if (platform === 'win32') { + downloadUrl += 'beta-windows.zip' + checksum = '3E0D684E7564862CBF43E38B9E29DD087052DE19D76C525D6F08C37D211A4381' + } + else { return null } + return {url: downloadUrl, checksum: checksum} } @@ -140,20 +166,42 @@ 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() { + + 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(); } /** * @return {string} */ function getTargetArch() { - return process.env.PHANTOMJS_ARCH || process.arch + return process.env.PHANTOMJS_ARCH || os.arch(); } module.exports = { checkPhantomjsVersion: checkPhantomjsVersion, getDownloadSpec: getDownloadSpec, getTargetPlatform: getTargetPlatform, + getTargetPlatformRelease: getTargetPlatformRelease, getTargetArch: getTargetArch, findValidPhantomJsBinary: findValidPhantomJsBinary, verifyChecksum: verifyChecksum, diff --git a/package.json b/package.json index ccd9fadea..85dd04040 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", @@ -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",