Permalink
Browse files

Simplified caching strategy: If node_modules directory is checked int…

…o source control, rebuild any native deps. Otherwise, restore from the build cache.
  • Loading branch information...
zeke committed Nov 25, 2013
1 parent 347a77b commit ae0756bdbec52315a5221edf0514bb8a7cf0d135
Showing with 2,790 additions and 176 deletions.
  1. +10 −18 bin/compile
  2. +4 −4 bin/test
  3. 0 test/{shrinkwrap → modules-checked-in}/README.md
  4. +191 −0 test/modules-checked-in/node_modules/hashish/README.markdown
  5. +9 −0 test/modules-checked-in/node_modules/hashish/examples/chain.js
  6. +7 −0 test/modules-checked-in/node_modules/hashish/examples/map.js
  7. +253 −0 test/modules-checked-in/node_modules/hashish/index.js
  8. 0 ...es/euclidean-distance → modules-checked-in/node_modules/hashish/node_modules/traverse}/.npmignore
  9. +3 −0 test/modules-checked-in/node_modules/hashish/node_modules/traverse/.travis.yml
  10. +24 −0 test/modules-checked-in/node_modules/hashish/node_modules/traverse/LICENSE
  11. +16 −0 test/modules-checked-in/node_modules/hashish/node_modules/traverse/examples/json.js
  12. +15 −0 test/modules-checked-in/node_modules/hashish/node_modules/traverse/examples/leaves.js
  13. +8 −0 test/modules-checked-in/node_modules/hashish/node_modules/traverse/examples/negative.js
  14. +10 −0 test/modules-checked-in/node_modules/hashish/node_modules/traverse/examples/scrub.js
  15. +38 −0 test/modules-checked-in/node_modules/hashish/node_modules/traverse/examples/stringify.js
  16. +314 −0 test/modules-checked-in/node_modules/hashish/node_modules/traverse/index.js
  17. +72 −0 test/modules-checked-in/node_modules/hashish/node_modules/traverse/package.json
  18. +209 −0 test/modules-checked-in/node_modules/hashish/node_modules/traverse/readme.markdown
  19. +117 −0 test/modules-checked-in/node_modules/hashish/node_modules/traverse/test/circular.js
  20. +37 −0 test/modules-checked-in/node_modules/hashish/node_modules/traverse/test/date.js
  21. +240 −0 test/modules-checked-in/node_modules/hashish/node_modules/traverse/test/equal.js
  22. +11 −0 test/modules-checked-in/node_modules/hashish/node_modules/traverse/test/error.js
  23. +15 −0 test/modules-checked-in/node_modules/hashish/node_modules/traverse/test/has.js
  24. +17 −0 test/modules-checked-in/node_modules/hashish/node_modules/traverse/test/instance.js
  25. +43 −0 test/modules-checked-in/node_modules/hashish/node_modules/traverse/test/interface.js
  26. +49 −0 test/modules-checked-in/node_modules/hashish/node_modules/traverse/test/json.js
  27. +31 −0 test/modules-checked-in/node_modules/hashish/node_modules/traverse/test/keys.js
  28. +22 −0 test/modules-checked-in/node_modules/hashish/node_modules/traverse/test/leaves.js
  29. +96 −0 test/modules-checked-in/node_modules/hashish/node_modules/traverse/test/lib/deep_equal.js
  30. +300 −0 test/modules-checked-in/node_modules/hashish/node_modules/traverse/test/mutability.js
  31. +21 −0 test/modules-checked-in/node_modules/hashish/node_modules/traverse/test/negative.js
  32. +11 −0 test/modules-checked-in/node_modules/hashish/node_modules/traverse/test/obj.js
  33. +37 −0 test/modules-checked-in/node_modules/hashish/node_modules/traverse/test/siblings.js
  34. +44 −0 test/modules-checked-in/node_modules/hashish/node_modules/traverse/test/stop.js
  35. +36 −0 test/modules-checked-in/node_modules/hashish/node_modules/traverse/test/stringify.js
  36. +36 −0 test/modules-checked-in/node_modules/hashish/node_modules/traverse/test/subexpr.js
  37. +56 −0 test/modules-checked-in/node_modules/hashish/node_modules/traverse/test/super_deep.js
  38. +22 −0 test/modules-checked-in/node_modules/hashish/node_modules/traverse/testling/leaves.js
  39. +46 −0 test/modules-checked-in/node_modules/hashish/package.json
  40. +250 −0 test/modules-checked-in/node_modules/hashish/test/hash.js
  41. +69 −0 test/modules-checked-in/node_modules/hashish/test/property.js
  42. +1 −1 test/{shrinkwrap → modules-checked-in}/package.json
  43. +0 −38 test/shrinkwrap/node_modules/euclidean-distance/README.md
  44. +0 −23 test/shrinkwrap/node_modules/euclidean-distance/index.js
  45. +0 −39 test/shrinkwrap/node_modules/euclidean-distance/package.json
  46. +0 −41 test/shrinkwrap/node_modules/euclidean-distance/test/indexTest.js
  47. +0 −2 test/shrinkwrap/node_modules/euclidean-distance/test/mocha.opts
  48. +0 −10 test/shrinkwrap/npm-shrinkwrap.json
View
@@ -6,7 +6,7 @@ set -o pipefail # don't ignore exit codes when piping output
# Configure directories
build_dir=$1
-cache_basedir=$2
+cache_dir=$2
bp_dir=$(cd $(dirname $0); cd ..; pwd)
# Load some convenience functions like status(), echo(), and indent()
@@ -54,23 +54,15 @@ PATH=$PATH:$build_dir/vendor/node/bin
# Run subsequent node/npm commands from the build path
cd $build_dir
-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
-
-if test -d $cache_dir; then
+# If node_modules directory is checked into source control then
+# rebuild any native deps. Otherwise, restore from the build cache.
+if test -d $build_dir/node_modules; then
+ status "Using existing node_modules directory"
+ status "Rebuilding any native dependencies"
+ npm rebuild 2>&1 | indent
+elif test -d $cache_dir/node_modules; then
status "Restoring node_modules from cache"
- test -d $cache_dir/node_modules && cp -r $cache_dir/node_modules $build_dir/
+ cp -r $cache_dir/node_modules $build_dir/
fi
# Make npm output to STDOUT instead of its default STDERR
@@ -80,7 +72,7 @@ npm install --production 2>&1 | indent
status "Pruning unused dependencies"
npm prune 2>&1 | indent
-status "Caching node_modules for future builds"
+status "Caching node_modules directory 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/
View
@@ -70,10 +70,10 @@ testNodeModulesCached() {
assertEquals "1" "$(ls -1 $cache/ | wc -l)"
}
-testShrinkwrap() {
- compile "shrinkwrap"
- assertCaptured "Found npm-shrinkwrap.json"
- assertNotCaptured "PRO TIP: Use npm shrinkwrap"
+testModulesCheckedIn() {
+ compile "modules-checked-in"
+ assertCaptured "Using existing node_modules directory"
+ assertCaptured "Rebuilding any native dependencies"
assertCapturedSuccess
}
File renamed without changes.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit ae0756b

Please sign in to comment.