diff --git a/bin/compile b/bin/compile index bb7c76053..7cbd2dd5a 100755 --- a/bin/compile +++ b/bin/compile @@ -1,7 +1,7 @@ #!/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 | indent - status "Installing dependencies" - npm install --production | indent +status "Pruning unused dependencies" +npm prune | 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" diff --git a/bin/test b/bin/test index 4b7e4918f..52dc50a58 100755 --- a/bin/test +++ b/bin/test @@ -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 } @@ -68,6 +69,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 +104,6 @@ testNodeModulesCached() { # assertCapturedError 1 "not found among available versions" # } - - # Utils pushd $(dirname 0) >/dev/null diff --git a/test/shrinkwrap/README.md b/test/shrinkwrap/README.md new file mode 100644 index 000000000..cda334ae1 --- /dev/null +++ b/test/shrinkwrap/README.md @@ -0,0 +1 @@ +A fake README, to keep npm from polluting stderr. \ No newline at end of file diff --git a/test/shrinkwrap/node_modules/euclidean-distance/.npmignore b/test/shrinkwrap/node_modules/euclidean-distance/.npmignore new file mode 100644 index 000000000..3c3629e64 --- /dev/null +++ b/test/shrinkwrap/node_modules/euclidean-distance/.npmignore @@ -0,0 +1 @@ +node_modules diff --git a/test/shrinkwrap/node_modules/euclidean-distance/README.md b/test/shrinkwrap/node_modules/euclidean-distance/README.md new file mode 100644 index 000000000..139f5ff0b --- /dev/null +++ b/test/shrinkwrap/node_modules/euclidean-distance/README.md @@ -0,0 +1,38 @@ +# 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. + + + +## 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 diff --git a/test/shrinkwrap/node_modules/euclidean-distance/index.js b/test/shrinkwrap/node_modules/euclidean-distance/index.js new file mode 100644 index 000000000..1204c2e73 --- /dev/null +++ b/test/shrinkwrap/node_modules/euclidean-distance/index.js @@ -0,0 +1,23 @@ +// 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 diff --git a/test/shrinkwrap/node_modules/euclidean-distance/package.json b/test/shrinkwrap/node_modules/euclidean-distance/package.json new file mode 100644 index 000000000..574ccc7a2 --- /dev/null +++ b/test/shrinkwrap/node_modules/euclidean-distance/package.json @@ -0,0 +1,39 @@ +{ + "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\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@*" +} diff --git a/test/shrinkwrap/node_modules/euclidean-distance/test/indexTest.js b/test/shrinkwrap/node_modules/euclidean-distance/test/indexTest.js new file mode 100644 index 000000000..80015eadd --- /dev/null +++ b/test/shrinkwrap/node_modules/euclidean-distance/test/indexTest.js @@ -0,0 +1,41 @@ +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]))); + }) + + }) + +}) diff --git a/test/shrinkwrap/node_modules/euclidean-distance/test/mocha.opts b/test/shrinkwrap/node_modules/euclidean-distance/test/mocha.opts new file mode 100644 index 000000000..f633acdac --- /dev/null +++ b/test/shrinkwrap/node_modules/euclidean-distance/test/mocha.opts @@ -0,0 +1,2 @@ +--reporter spec +--ui tdd diff --git a/test/shrinkwrap/npm-shrinkwrap.json b/test/shrinkwrap/npm-shrinkwrap.json new file mode 100644 index 000000000..c7f0b5505 --- /dev/null +++ b/test/shrinkwrap/npm-shrinkwrap.json @@ -0,0 +1,10 @@ +{ + "name": "node-buildpack-test-app", + "version": "0.0.1", + "dependencies": { + "euclidean-distance": { + "version": "0.1.0", + "from": "euclidean-distance@*" + } + } +} diff --git a/test/shrinkwrap/package.json b/test/shrinkwrap/package.json new file mode 100644 index 000000000..3b195dd88 --- /dev/null +++ b/test/shrinkwrap/package.json @@ -0,0 +1,15 @@ +{ + "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" + } +} diff --git a/test/stable-node/package.json b/test/stable-node/package.json index fe43c0312..d5561df40 100644 --- a/test/stable-node/package.json +++ b/test/stable-node/package.json @@ -6,6 +6,9 @@ "type" : "git", "url" : "http://github.com/example/example.git" }, + "dependencies": { + "hashish": "*" + }, "engines": { "node": "~0.10.0" }