Skip to content

Commit

Permalink
Merge pull request #56 from prebuild/dependencies
Browse files Browse the repository at this point in the history
update dependencies and node versions
  • Loading branch information
ralphtheninja committed Jan 23, 2018
2 parents 63721a8 + 8608b92 commit cd60f37
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 111 deletions.
14 changes: 6 additions & 8 deletions .travis.yml
@@ -1,10 +1,8 @@
language: node_js
node_js:
- '9'
- '8'
- '7'
- '6'
- '5'
- '4'
- '0.12'
- '0.10'
- 9
- 8
- 7
- 6
- 5
- 4
9 changes: 5 additions & 4 deletions README.md
@@ -1,6 +1,7 @@
# prebuild-install

[![Build Status](https://travis-ci.org/prebuild/prebuild-install.svg?branch=master)](https://travis-ci.org/prebuild/prebuild-install)
[![david](https://david-dm.org/prebuild/prebuild-install.svg)](https://david-dm.org/prebuild/prebuild-install)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)

> A command line tool for easily install prebuilds for multiple version of node/iojs on a specific platform.
Expand All @@ -20,7 +21,7 @@ Change your package.json install script to:

### Requirements

You need to provide prebuilds made by [prebuild](https://github.com/mafintosh/prebuild)
You need to provide prebuilds made by [prebuild](https://github.com/mafintosh/prebuild).

### Help
```
Expand All @@ -42,13 +43,13 @@ When `prebuild-install` is run via an `npm` script, options
arguments given to the `npm` command.

### Custom binaries
The end user can override binary download location through environment variables in their .npmrc file.
The end user can override binary download location through environment variables in their .npmrc file.
The variable needs to meet the mask `% your package name %_binary_host` or `% your package name %_binary_host_mirror`. For example:
```
leveldown_binary_host=http://overriden-host.com/overriden-path
```
Note that the package version subpath and file name will still be appended.
So if you are installing `leveldown@1.2.3` the resulting url will be:
Note that the package version subpath and file name will still be appended.
So if you are installing `leveldown@1.2.3` the resulting url will be:
```
http://overriden-host.com/overriden-path/v1.2.3/leveldown-v1.2.3-node-v57-win32-x64.tar.gz
```
Expand Down
35 changes: 14 additions & 21 deletions download.js
Expand Up @@ -26,23 +26,23 @@ function downloadPrebuild (opts, cb) {
if (opts.nolocal) return download()

log.info('looking for local prebuild @', localPrebuild)
fs.exists(localPrebuild, function (exists) {
if (exists) {
log.info('found local prebuild')
cachedPrebuild = localPrebuild
return unpack()
fs.access(localPrebuild, fs.R_OK | fs.W_OK, function (err) {
if (err && err.code === 'ENOENT') {
return download()
}

download()
log.info('found local prebuild')
cachedPrebuild = localPrebuild
unpack()
})

function download () {
ensureNpmCacheDir(function (err) {
if (err) return onerror(err)

log.info('looking for cached prebuild @', cachedPrebuild)
fs.exists(cachedPrebuild, function (exists) {
if (exists) {
fs.access(cachedPrebuild, fs.R_OK | fs.W_OK, function (err) {
if (!(err && err.code === 'ENOENT')) {
log.info('found cached prebuild')
return unpack()
}
Expand Down Expand Up @@ -146,19 +146,12 @@ function downloadPrebuild (opts, cb) {

function ensureNpmCacheDir (cb) {
var cacheFolder = util.npmCache()
if (fs.access) {
fs.access(cacheFolder, fs.R_OK | fs.W_OK, function (err) {
if (err && err.code === 'ENOENT') {
return makeNpmCacheDir()
}
cb(err)
})
} else {
fs.exists(cacheFolder, function (exists) {
if (!exists) return makeNpmCacheDir()
cb()
})
}
fs.access(cacheFolder, fs.R_OK | fs.W_OK, function (err) {
if (err && err.code === 'ENOENT') {
return makeNpmCacheDir()
}
cb(err)
})

function makeNpmCacheDir () {
log.info('npm cache directory missing, creating it...')
Expand Down
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -28,9 +28,9 @@
"noop-logger": "^0.1.1",
"npmlog": "^4.0.1",
"os-homedir": "^1.0.1",
"pump": "^1.0.1",
"pump": "^2.0.1",
"rc": "^1.1.6",
"simple-get": "^1.4.2",
"simple-get": "^2.7.0",
"tar-fs": "^1.13.0",
"tunnel-agent": "^0.6.0",
"xtend": "4.0.1"
Expand All @@ -39,7 +39,7 @@
"a-native-module": "^1.0.0",
"nsp": "^2.3.0",
"rimraf": "^2.5.2",
"standard": "^8.6.0",
"standard": "^10.0.3",
"tape": "^4.5.1"
},
"bin": "./bin.js",
Expand Down
81 changes: 8 additions & 73 deletions test/download-test.js
Expand Up @@ -12,52 +12,17 @@ var build = path.join(__dirname, 'build')
var unpacked = path.join(build, 'Release/leveldown.node')

test('downloading from GitHub, not cached', function (t) {
t.plan(14)
t.plan(10)
rm.sync(build)
rm.sync(util.prebuildCache())

var opts = getOpts()
var downloadUrl = util.getDownloadUrl(opts)
var cachedPrebuild = util.cachedPrebuild(downloadUrl)
var npmCache = util.npmCache()
var tempFile

var existsCallNum = 0
var _access = fs.access ? fs.access.bind(fs) : fs.access
var _exists = fs.exists.bind(fs)
if (_access) {
fs.access = function (path, a, cb) {
if (existsCallNum++ === 0) {
t.equal(path, npmCache, 'fs.exists called for npm cache')
_access(path, cb)
}
}
}
fs.exists = function (path, cb) {
if (existsCallNum++ === 0) {
t.equal(path, npmCache, 'fs.exists called for npm cache')
_exists(path, cb)
} else {
t.equal(path, cachedPrebuild, 'fs.exists called for prebuild')
_exists(path, function (exists) {
t.equal(exists, false, 'prebuild should be cached')
cb(exists)
})
}
}

var mkdirCount = 0
var _mkdir = fs.mkdir.bind(fs)
fs.mkdir = function () {
var args = [].slice.call(arguments)
if (mkdirCount++ === 0) {
t.equal(args[0], util.prebuildCache(), 'fs.mkdir called for prebuildCache')
}
_mkdir.apply(fs, arguments)
}

var writeStreamCount = 0
var _createWriteStream = fs.createWriteStream.bind(fs)
var _createWriteStream = fs.createWriteStream
fs.createWriteStream = function (path) {
if (writeStreamCount++ === 0) {
tempFile = path
Expand All @@ -68,7 +33,7 @@ test('downloading from GitHub, not cached', function (t) {
return _createWriteStream(path)
}

var _createReadStream = fs.createReadStream.bind(fs)
var _createReadStream = fs.createReadStream
fs.createReadStream = function (path) {
t.equal(path, cachedPrebuild, 'createReadStream called for cachedPrebuild')
return _createReadStream(path)
Expand All @@ -89,54 +54,26 @@ test('downloading from GitHub, not cached', function (t) {
t.equal(fs.existsSync(cachedPrebuild), true, 'prebuild was cached')
t.equal(fs.existsSync(unpacked), true, unpacked + ' should exist')
t.equal(fs.existsSync(tempFile), false, 'temp file should be gone')
fs.exists = _exists
fs.access = _access
fs.mkdir = _mkdir
fs.createWriteStream = _createWriteStream
fs.createReadStream = _createReadStream
})
})

test('cached prebuild', function (t) {
t.plan(8)
t.plan(5)
rm.sync(build)

var opts = getOpts()
var downloadUrl = util.getDownloadUrl(opts)
var cachedPrebuild = util.cachedPrebuild(downloadUrl)
var npmCache = util.npmCache()

var existsCallNum = 0
var _access = fs.access ? fs.access.bind(fs) : fs.access
var _exists = fs.exists.bind(fs)
if (_access) {
fs.access = function (path, a, cb) {
if (existsCallNum++ === 0) {
t.equal(path, npmCache, 'fs.exists called for npm cache')
_access(path, cb)
}
}
}
fs.exists = function (path, cb) {
if (existsCallNum++ === 0) {
t.equal(path, npmCache, 'fs.exists called for npm cache')
_exists(path, cb)
} else {
t.equal(path, cachedPrebuild, 'fs.exists called for prebuild')
_exists(path, function (exists) {
t.equal(exists, true, 'prebuild should be cached')
cb(exists)
})
}
}

var _createWriteStream = fs.createWriteStream.bind(fs)
var _createWriteStream = fs.createWriteStream
fs.createWriteStream = function (path) {
t.ok(/\.node$/i.test(path), 'this is the unpacked file')
return _createWriteStream(path)
}

var _createReadStream = fs.createReadStream.bind(fs)
var _createReadStream = fs.createReadStream
fs.createReadStream = function (path) {
t.equal(path, cachedPrebuild, 'createReadStream called for cachedPrebuild')
return _createReadStream(path)
Expand All @@ -149,8 +86,6 @@ test('cached prebuild', function (t) {
t.equal(fs.existsSync(unpacked), true, unpacked + ' should exist')
fs.createReadStream = _createReadStream
fs.createWriteStream = _createWriteStream
fs.exists = _exists
fs.access = _access
})
})

Expand All @@ -165,7 +100,7 @@ test('non existing host should fail with no dangling temp file', function (t) {
var downloadUrl = util.getDownloadUrl(opts)
var cachedPrebuild = util.cachedPrebuild(downloadUrl)

var _createWriteStream = fs.createWriteStream.bind(fs)
var _createWriteStream = fs.createWriteStream
fs.createWriteStream = function (path) {
t.ok(false, 'no temporary file should be written')
return _createWriteStream(path)
Expand Down Expand Up @@ -223,7 +158,7 @@ test('error during download should fail with no dangling temp file', function (t
var cachedPrebuild = util.cachedPrebuild(downloadUrl)
var tempFile

var _createWriteStream = fs.createWriteStream.bind(fs)
var _createWriteStream = fs.createWriteStream
fs.createWriteStream = function (path) {
tempFile = path
t.ok(/\.tmp$/i.test(path), 'this is the temporary file')
Expand Down
4 changes: 2 additions & 2 deletions test/util-test.js
Expand Up @@ -33,8 +33,8 @@ test('tempFile() ends with pid and random number', function (t) {
var match = regexp.exec(tempFile)
t.ok(match, 'matches')
t.equal(match[1], cached, 'starts with cached file name')
fs.exists(tempFile, function (exists) {
t.equal(exists, false, 'file should not exist yet')
fs.access(tempFile, fs.R_OK | fs.W_OK, function (err) {
t.ok(err && err.code === 'ENOENT', 'file should not exist yet')
t.end()
})
})
Expand Down

0 comments on commit cd60f37

Please sign in to comment.