Commit 3b70e063 authored by Zeke Sikelianos's avatar Zeke Sikelianos

Merge pull request #58 from heroku/shrinkwrap

:shipit:
parents 83104b4f c31bd679
#!/usr/bin/env bash
set -e # fail fast
set -o pipefail # don't ignore piped exit codes
set -o pipefail # don't ignore exit codes when piping output
# set -x # enable debugging
# Configure directories
......@@ -9,7 +9,7 @@ build_dir=$1
cache_basedir=$2
bp_dir=$(cd $(dirname $0); cd ..; pwd)
# Load some convenience functions like status() echo(), indent
# Load some convenience functions like status() echo(), indent()
source $bp_dir/bin/common.sh
# Output npm debug info on error
......@@ -54,37 +54,35 @@ PATH=$PATH:$build_dir/vendor/node/bin
# Run subsequent node/npm commands from the build path
cd $build_dir
# Configure cache directory
package_checksum=$(cat $build_dir/package.json | md5sum | awk '{print $1}')
cache_dir="$cache_basedir/$package_checksum"
if test -f $build_dir/npm-shrinkwrap.json; then
# Use npm-shrinkwrap.json's checksum as the cachebuster
status "Found npm-shrinkwrap.json"
shrinkwrap_checksum=$(cat $build_dir/npm-shrinkwrap.json | md5sum | awk '{print $1}')
cache_dir="$cache_basedir/$shrinkwrap_checksum"
test -d $cache_dir && status "npm-shrinkwrap.json unchanged since last build"
else
# Fall back to package.json as the cachebuster.
protip "Use npm shrinkwrap to lock down dependency versions"
package_json_checksum=$(cat $build_dir/package.json | md5sum | awk '{print $1}')
cache_dir="$cache_basedir/$package_json_checksum"
test -d $cache_dir && status "package.json unchanged since last build"
fi
# Restore from cache if package.json hasn't changed
if test -d $cache_dir; then
status "package.json unchanged since last build"
status "Restoring node_modules from cache"
test -d $cache_dir/node_modules && cp -r $cache_dir/node_modules $build_dir/
fi
# If any scripts are defined in package.json, trigger them.
# https://npmjs.org/doc/misc/npm-scripts.html
hook_scripts=$(cat $build_dir/package.json | $bp_dir/vendor/jq -r .scripts)
if [ "$hook_scripts" != "null" ]; then
status "Running npm install to trigger script hooks"
npm install --production | indent
fi
else
status "Rebuilding dependencies"
npm rebuild | indent
status "Installing dependencies"
npm install --production 2>&1 | indent
status "Installing dependencies"
npm install --production | indent
status "Pruning unused dependencies"
npm prune 2>&1 | indent
status "Caching node_modules for future builds"
rm -rf $cache_dir
mkdir -p $cache_dir
test -d $build_dir/node_modules && cp -r $build_dir/node_modules $cache_dir/
fi
status "Caching node_modules for future builds"
rm -rf $cache_dir
mkdir -p $cache_dir
test -d $build_dir/node_modules && cp -r $build_dir/node_modules $cache_dir/
# Update the PATH
status "Building runtime environment"
......
......@@ -37,7 +37,8 @@ testDangerousRangeGreaterThan() {
testStableVersion() {
compile "stable-node"
assertNotCaptured "PRO TIP"
assertNotCaptured "PRO TIP: Avoid using semver"
assertNotCaptured "PRO TIP: Specify"
assertCaptured "Resolved node version"
assertCapturedSuccess
}
......@@ -58,7 +59,8 @@ testProfileCreated() {
testInvalidDependency() {
compile "invalid-dependency"
assertCapturedError 1 "not in the npm registry"
assertCaptured "not in the npm registry"
assertCapturedError 1 ""
}
testNodeModulesCached() {
......@@ -68,6 +70,13 @@ testNodeModulesCached() {
assertEquals "1" "$(ls -1 $cache/ | wc -l)"
}
testShrinkwrap() {
compile "shrinkwrap"
assertCaptured "Found npm-shrinkwrap.json"
assertNotCaptured "PRO TIP: Use npm shrinkwrap"
assertCapturedSuccess
}
# Pending Tests
# testNodeBinariesAddedToPath() {
......@@ -96,8 +105,6 @@ testNodeModulesCached() {
# assertCapturedError 1 "not found among available versions"
# }
# Utils
pushd $(dirname 0) >/dev/null
......
A fake README, to keep npm from polluting stderr.
\ No newline at end of file
# Euclidean Distance
euclidean-distance is a [browserify](https://github.com/substack/node-browserify#browserify)-friendly npm module
for calculating the [Euclidean distance](http://en.wikipedia.org/wiki/Euclidean_distance#Three_dimensions)
been two points in 2D or 3D space.
<img src="http://upload.wikimedia.org/math/a/0/5/a056c1b3e4b1c72be81acf62b9e574ca.png">
## Installation
```
npm install euclidean-distance --save
```
## Usage
```js
var d = require('euclidean-distance');
d([0,0], [1,0]);
// 1
d([0,0], [3,2]);
// 3.605551275463989
d([-7,-4,3], [17, 6, 2.5]);
// 26.004807247892
```
## Test
```
npm test
```
## License
[WTFPL](http://wtfpl.org/)
\ No newline at end of file
// http://en.wikipedia.org/wiki/Euclidean_distance#Three_dimensions
module.exports = function(a, b) {
// return Math.sqrt(
// Math.pow(a[0]-b[0], 2) +
// Math.pow(a[1]-b[1], 2) +
// Math.pow(a[2]-b[2], 2)
// )
// return Math.sqrt(
// [0,1,2].reduce(function(prev, current, i) {
// return prev + Math.pow(a[i]-b[i], 2);
// }, 0)
// );
var sum = 0;
var n;
for (n=0; n < a.length; n++) {
sum += Math.pow(a[n]-b[n], 2);
}
return Math.sqrt(sum);
}
\ No newline at end of file
{
"name": "euclidean-distance",
"version": "0.1.0",
"description": "Calculate the Euclidean distance been two points in 2D/3D/nD space.",
"main": "index.js",
"scripts": {
"test": "mocha"
},
"repository": {
"type": "git",
"url": "https://github.com/zeke/euclidean-distance"
},
"keywords": [
"distance",
"space",
"3d",
"2d",
"math",
"euclid",
"color",
"Lab",
"L*a*b*",
"Delta-E",
"dE",
"visualization",
"browser"
],
"author": {
"name": "zeke"
},
"license": "WTFPL",
"bugs": {
"url": "https://github.com/zeke/euclidean-distance/issues"
},
"readme": "# Euclidean Distance\n\neuclidean-distance is a [browserify](https://github.com/substack/node-browserify#browserify)-friendly npm module\nfor calculating the [Euclidean distance](http://en.wikipedia.org/wiki/Euclidean_distance#Three_dimensions)\nbeen two points in 2D or 3D space.\n\n<img src=\"http://upload.wikimedia.org/math/a/0/5/a056c1b3e4b1c72be81acf62b9e574ca.png\">\n\n## Installation\n\n```\nnpm install euclidean-distance --save\n```\n\n## Usage\n\n```js\nvar d = require('euclidean-distance');\n\nd([0,0], [1,0]);\n// 1\n\nd([0,0], [3,2]);\n// 3.605551275463989\n\nd([-7,-4,3], [17, 6, 2.5]);\n// 26.004807247892\n```\n\n## Test\n\n```\nnpm test\n```\n\n## License\n\n[WTFPL](http://wtfpl.org/)",
"readmeFilename": "README.md",
"_id": "euclidean-distance@0.1.0",
"_from": "euclidean-distance@*"
}
var assert = require("assert")
var euclid = require("../index")
describe('euclideanDistance', function(){
describe('2d', function(){
it('returns 1 when points are 1 unit away', function(){
assert.equal(1, euclid([0,0], [1,0]));
})
it('works with non-parallel points', function(){
var d = euclid([0,0], [3,2]) // 3.605551275463989
assert.equal(360, Math.floor(d*100));
})
it('handles with non-parallel points', function(){
var d = euclid([-1,0], [2,2]) // 3.605551275463989
assert.equal(360, Math.floor(d*100));
})
it('returns 0 when points are the same', function(){
assert.equal(0, euclid([3,5], [3,5]));
})
})
describe('3d', function(){
it('returns 1 when points are 1 unit away', function(){
assert.equal(1, euclid([0,0,0], [1,0,0]));
})
// http://www.calculatorsoup.com/calculators/geometry-solids/distance-two-points.php
it("works with numbers I didn't make up", function(){
assert.equal(26, Math.floor(euclid([-7,-4,3], [17, 6, 2.5])));
})
})
})
{
"name": "node-buildpack-test-app",
"version": "0.0.1",
"dependencies": {
"euclidean-distance": {
"version": "0.1.0",
"from": "euclidean-distance@*"
}
}
}
{
"name": "node-buildpack-test-app",
"version": "0.0.1",
"description": "node buildpack integration test app",
"repository" : {
"type" : "git",
"url" : "http://github.com/example/example.git"
},
"dependencies": {
"euclidean-distance": "*"
},
"engines": {
"node": "~0.10.0"
}
}
......@@ -6,6 +6,9 @@
"type" : "git",
"url" : "http://github.com/example/example.git"
},
"dependencies": {
"hashish": "*"
},
"engines": {
"node": "~0.10.0"
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment