Commit 778e2413 authored by Hunter Loftis's avatar Hunter Loftis

re-default to node_modules, use file check instead of yarn check

remove pure-lockfile

pure-lockfile

typo

removed extraneous yarn lock file

changelog
parent e5aaf7c6
# Node.js Buildpack Changelog # Node.js Buildpack Changelog
## Master
- Cache node_modules
- No longer run `yarn check`
## v96 (2017-01-27) ## v96 (2017-01-27)
- Clear caches from the slug - Clear caches from the slug
......
...@@ -10,7 +10,7 @@ unset GIT_DIR # Avoid GIT_DIR leak from previous build steps ...@@ -10,7 +10,7 @@ unset GIT_DIR # Avoid GIT_DIR leak from previous build steps
### Constants ### Constants
DEFAULT_CACHE=".npm .cache/yarn bower_components" DEFAULT_CACHE="node_modules bower_components"
### Configure directories ### Configure directories
...@@ -118,7 +118,7 @@ restore_cache() { ...@@ -118,7 +118,7 @@ restore_cache() {
if [ "$cache_status" == "valid" ]; then if [ "$cache_status" == "valid" ]; then
local cache_directories=$(get_cache_directories) local cache_directories=$(get_cache_directories)
if [ "$cache_directories" == "" ]; then if [ "$cache_directories" == "" ]; then
echo "Loading 3 from cacheDirectories (default):" echo "Loading 2 from cacheDirectories (default):"
restore_cache_directories "$BUILD_DIR" "$CACHE_DIR" "$DEFAULT_CACHE" restore_cache_directories "$BUILD_DIR" "$CACHE_DIR" "$DEFAULT_CACHE"
else else
echo "Loading $(echo $cache_directories | wc -w | xargs) from cacheDirectories (package.json):" echo "Loading $(echo $cache_directories | wc -w | xargs) from cacheDirectories (package.json):"
...@@ -157,14 +157,13 @@ cache_build() { ...@@ -157,14 +157,13 @@ cache_build() {
if ! ${NODE_MODULES_CACHE:-true}; then if ! ${NODE_MODULES_CACHE:-true}; then
echo "Skipping cache save (disabled by config)" echo "Skipping cache save (disabled by config)"
elif [ "$cache_directories" == "" ]; then elif [ "$cache_directories" == "" ]; then
echo "Saving 3 cacheDirectories (default):" echo "Saving 2 cacheDirectories (default):"
save_cache_directories "$BUILD_DIR" "$CACHE_DIR" "$DEFAULT_CACHE" save_cache_directories "$BUILD_DIR" "$CACHE_DIR" "$DEFAULT_CACHE"
else else
echo "Saving $(echo $cache_directories | wc -w | xargs) cacheDirectories (package.json):" echo "Saving $(echo $cache_directories | wc -w | xargs) cacheDirectories (package.json):"
save_cache_directories "$BUILD_DIR" "$CACHE_DIR" $cache_directories save_cache_directories "$BUILD_DIR" "$CACHE_DIR" $cache_directories
fi fi
save_signature save_signature
remove_caches_from_slug "$BUILD_DIR"
} }
header "Caching build" header "Caching build"
......
...@@ -56,12 +56,6 @@ restore_cache_directories() { ...@@ -56,12 +56,6 @@ restore_cache_directories() {
done done
} }
remove_caches_from_slug() {
local build_dir=${1:-}
rm -rf "$build_dir/.npm"
rm -rf "$build_dir/.cache/yarn"
}
clear_cache() { clear_cache() {
rm -rf $CACHE_DIR/node rm -rf $CACHE_DIR/node
mkdir -p $CACHE_DIR/node mkdir -p $CACHE_DIR/node
......
...@@ -27,17 +27,10 @@ run_if_present() { ...@@ -27,17 +27,10 @@ run_if_present() {
yarn_node_modules() { yarn_node_modules() {
local build_dir=${1:-} local build_dir=${1:-}
echo "Installing node modules (yarn.lock)" echo "Installing node modules (yarn.lock)"
cd "$build_dir" cd "$build_dir"
yarn install --pure-lockfile --ignore-engines --cache-folder $build_dir/.cache/yarn 2>&1 yarn install --pure-lockfile --ignore-engines 2>&1
# according to docs: "Verifies that versions of the package dependencies in the current project’s package.json matches that of yarn’s lock file."
# however, appears to also check for the presence of deps in node_modules, so must be run after install
if $(yarn check 1>/dev/null); then
echo "yarn.lock and package.json match"
else
echo "yarn.lock is outdated"
warning "yarn.lock is outdated." "run \`yarn install\`, commit the updated \`yarn.lock\`, and redeploy"
fi
} }
npm_node_modules() { npm_node_modules() {
...@@ -51,7 +44,7 @@ npm_node_modules() { ...@@ -51,7 +44,7 @@ npm_node_modules() {
else else
echo "Installing node modules (package.json)" echo "Installing node modules (package.json)"
fi fi
npm install --unsafe-perm --userconfig $build_dir/.npmrc --cache $build_dir/.npm 2>&1 npm install --unsafe-perm --userconfig $build_dir/.npmrc 2>&1
else else
echo "Skipping (no package.json)" echo "Skipping (no package.json)"
fi fi
......
#!/usr/bin/env bash #!/usr/bin/env bash
# See README.md for info on running these tests. # See README.md for info on running these tests.
testDisableCache() {
cache=$(mktmpdir)
env_dir=$(mktmpdir)
echo "true" > $env_dir/NODE_VERBOSE
compile "node-modules-cache-1" $cache $env_dir
assertCaptured "lodash@1.0.0"
assertEquals "1" "$(ls -1 $cache/node/node_modules | grep lodash | wc -l | tr -d ' ')"
assertCapturedSuccess
compile "node-modules-cache-2" $cache $env_dir
assertCaptured "lodash@1.0.0"
assertCaptured "Saving 2 cacheDirectories"
assertCapturedSuccess
echo "false" > $env_dir/NODE_MODULES_CACHE
compile "node-modules-cache-2" $cache $env_dir
assertCaptured "lodash@1.3.1"
assertNotCaptured "Saving 2 cacheDirectories"
assertCapturedSuccess
}
testNodeModulesCached() { testNodeModulesCached() {
cache=$(mktmpdir) cache=$(mktmpdir)
compile "caching" $cache compile "caching" $cache
assertCaptured "Saving 3 cacheDirectories (default)" assertCaptured "Saving 2 cacheDirectories (default)"
assertCaptured "- .npm" assertCaptured "- node_modules"
assertCaptured "- .cache/yarn (nothing to cache)"
assertCaptured "- bower_components (nothing to cache)" assertCaptured "- bower_components (nothing to cache)"
assertEquals "1" "$(ls -1 $cache/node/.npm | grep express | wc -l | tr -d ' ')" assertEquals "1" "$(ls -1 $cache/node/node_modules | grep express | wc -l | tr -d ' ')"
assertCapturedSuccess assertCapturedSuccess
} }
...@@ -26,16 +47,16 @@ testBuildWithCache() { ...@@ -26,16 +47,16 @@ testBuildWithCache() {
compile "stable-node" $cache compile "stable-node" $cache
assertCaptured "Skipping cache restore (new runtime" assertCaptured "Skipping cache restore (new runtime"
assertEquals "1" "$(ls -1 $cache/node/.npm | grep hashish | wc -l | tr -d ' ')" assertEquals "1" "$(ls -1 $cache/node/node_modules | grep hashish | wc -l | tr -d ' ')"
assertCapturedSuccess assertCapturedSuccess
compile "stable-node" $cache compile "stable-node" $cache
assertNotCaptured "- .npm (not cached - skipping)" assertNotCaptured "- node_modules (not cached - skipping)"
assertCapturedSuccess assertCapturedSuccess
rm -rf "$cache/node/.npm" rm -rf "$cache/node/node_modules"
compile "stable-node" $cache compile "stable-node" $cache
assertCaptured "- .npm (not cached - skipping)" assertCaptured "- node_modules (not cached - skipping)"
assertCapturedSuccess assertCapturedSuccess
} }
......
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