Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch 'master' of https://github.com/heroku/heroku-buildpack-n…

  • Loading branch information...
commit 2168fa2da5e7c8adf4ef60922afc2b0199f404de 2 parents 61540c1 + 97a5856
Matthias Buchetics authored March 04, 2014

Showing 1 changed file with 35 additions and 6 deletions. Show diff stats Hide diff stats

  1. 41  bin/compile
41  bin/compile
@@ -61,12 +61,25 @@ if test -d $build_dir/node_modules; then
61 61
   status "Found existing node_modules directory; skipping cache"
62 62
   status "Rebuilding any native dependencies"
63 63
   npm rebuild 2>&1 | indent
64  
-elif test -d $cache_dir/node_modules; then
  64
+elif test -d $cache_dir/node/node_modules; then
65 65
   status "Restoring node_modules directory from cache"
66  
-  cp -r $cache_dir/node_modules $build_dir/
  66
+  cp -r $cache_dir/node/node_modules $build_dir/
67 67
 
68 68
   status "Pruning cached dependencies not specified in package.json"
69 69
   npm prune 2>&1 | indent
  70
+
  71
+  if test -f $cache_dir/node/.heroku/node-version && [ $(cat $cache_dir/node/.heroku/node-version) != "$node_version" ]; then
  72
+    status "Node version changed since last build; rebuilding dependencies"
  73
+    npm rebuild 2>&1 | indent
  74
+  fi
  75
+
  76
+fi
  77
+
  78
+# Handle npm's new cert bug
  79
+# http://blog.npmjs.org/post/78085451721/npms-self-signed-certificate-is-no-more
  80
+if [ ! -f "$build_dir/.npmrc" ]; then
  81
+  status "Writing a custom .npmrc to circumvent npm bugs"
  82
+  echo "ca=" > "$build_dir/.npmrc"
70 83
 fi
71 84
 
72 85
 # Scope config var availability only to `npm install`
@@ -81,10 +94,26 @@ fi
81 94
   npm install --userconfig $build_dir/.npmrc --production 2>&1 | indent
82 95
 )
83 96
 
84  
-status "Caching node_modules directory for future builds"
85  
-rm -rf $cache_dir/node_modules
86  
-mkdir -p $cache_dir
87  
-test -d $build_dir/node_modules && cp -r $build_dir/node_modules $cache_dir/
  97
+# Persist goodies like node-version in the slug
  98
+mkdir -p $build_dir/.heroku
  99
+
  100
+# Save resolved node version in the slug for later reference
  101
+echo $node_version > $build_dir/.heroku/node-version
  102
+
  103
+# Purge node-related cached content, being careful not to purge the top-level
  104
+# cache, for the sake of heroku-buildpack-multi apps.
  105
+rm -rf $cache_dir/node_modules # (for apps still on the older caching strategy)
  106
+rm -rf $cache_dir/node
  107
+mkdir -p $cache_dir/node
  108
+
  109
+# If app has a node_modules directory, cache it.
  110
+if test -d $build_dir/node_modules; then
  111
+  status "Caching node_modules directory for future builds"
  112
+  cp -r $build_dir/node_modules $cache_dir/node
  113
+fi
  114
+
  115
+# Copy goodies to the cache
  116
+cp -r $build_dir/.heroku $cache_dir/node
88 117
 
89 118
 status "Cleaning up node-gyp and npm artifacts"
90 119
 rm -rf "$build_dir/.node-gyp"

0 notes on commit 2168fa2

Please sign in to comment.
Something went wrong with that request. Please try again.