Skip to content
This repository has been archived by the owner on Jul 24, 2019. It is now read-only.

Commit

Permalink
Merge pull request #277 from corbinu/master
Browse files Browse the repository at this point in the history
Replace ncp, mkdirp, and rimraf with fs-extra for io.js support
  • Loading branch information
nicks committed Jan 27, 2015
2 parents d3b860c + db57e92 commit f3dcca8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 21 deletions.
23 changes: 5 additions & 18 deletions install.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@ var requestProgress = require('request-progress')
var progress = require('progress')
var AdmZip = require('adm-zip')
var cp = require('child_process')
var fs = require('fs')
var fs = require('fs-extra')
var helper = require('./lib/phantomjs')
var kew = require('kew')
var mkdirp = require('mkdirp')
var ncp = require('ncp')
var npmconf = require('npmconf')
var path = require('path')
var request = require('request')
var rimraf = require('rimraf')
var url = require('url')
var util = require('util')
var which = require('which')
Expand Down Expand Up @@ -184,7 +181,7 @@ function findSuitableTempDirectory(npmConf) {
var candidatePath = path.join(candidateTmpDirs[i], 'phantomjs')

try {
mkdirp.sync(candidatePath, '0777')
fs.mkdirsSync(candidatePath, '0777')
// Make double sure we have 0777 permissions; some operating systems
// default umask does not allow write by default.
fs.chmodSync(candidatePath, '0777')
Expand Down Expand Up @@ -300,7 +297,7 @@ function extractDownload(filePath) {
var extractedPath = filePath + '-extract-' + Date.now()
var options = {cwd: extractedPath}

mkdirp.sync(extractedPath, '0777')
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')
Expand Down Expand Up @@ -334,28 +331,18 @@ function extractDownload(filePath) {

function copyIntoPlace(extractedPath, targetPath) {
console.log('Removing', targetPath)
return kew.nfcall(rimraf, targetPath).then(function () {
return kew.nfcall(fs.remove, targetPath).then(function () {
// Look for the extracted directory, so we can rename it.
var files = fs.readdirSync(extractedPath)
for (var i = 0; i < files.length; i++) {
var file = path.join(extractedPath, files[i])
if (fs.statSync(file).isDirectory() && file.indexOf(helper.version) != -1) {
console.log('Copying extracted folder', file, '->', targetPath)
return kew.nfcall(ncp, file, targetPath)
return kew.nfcall(fs.move, file, targetPath)
}
}

console.log('Could not find extracted file', files)
throw new Error('Could not find extracted file')
})
.then(function () {
// Cleanup extracted directory after it's been copied
console.log('Removing', extractedPath)
return kew.nfcall(rimraf, extractedPath).fail(function (e) {
// Swallow the error quietly.
console.warn(e)
console.warn('Unable to remove temporary files at "' + extractedPath +
'", see https://github.com/Obvious/phantomjs/issues/108 for details.')
})
})
}
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,12 @@
},
"dependencies": {
"adm-zip": "0.4.4",
"fs-extra": "^0.15.0",
"kew": "0.4.0",
"ncp": "~1.0.1",
"npmconf": "2.0.9",
"mkdirp": "0.5.0",
"progress": "1.1.8",
"request": "2.42.0",
"request-progress": "0.3.1",
"rimraf": "~2.2.8",
"which": "~1.0.5"
},
"devDependencies": {
Expand Down

0 comments on commit f3dcca8

Please sign in to comment.