Commit c2c7fd37 authored by Jeremy Morrell's avatar Jeremy Morrell Committed by GitHub

Move the default Yarn and npm cache directories to a tmp dir (#459)

* Move the default Yarn cache directory to a tmp dir
* Move the default npm cache directory to a tmp dir
parent acc99022
......@@ -20,6 +20,10 @@ ENV_DIR=${3:-}
BP_DIR=$(cd $(dirname ${0:-}); cd ..; pwd)
STDLIB_FILE=$(mktemp -t stdlib.XXXXX)
### Configure package manager cache directories
[ ! "$YARN_CACHE_FOLDER" ] && YARN_CACHE_FOLDER=$(mktemp -d -t yarncache.XXXXX)
[ ! "$NPM_CONFIG_CACHE" ] && NPM_CONFIG_CACHE=$(mktemp -d -t npmcache.XXXXX)
### Load dependencies
curl --silent --retry 5 --retry-max-time 15 'https://lang-common.s3.amazonaws.com/buildpack-stdlib/v7/stdlib.sh' > "$STDLIB_FILE"
......
{
"name": "yarn",
"version": "1.0.0",
"lockfileVersion": 1,
"dependencies": {
"lodash": {
"version": "4.17.4",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.4.tgz",
"integrity": "sha1-eCA6TRwyiuHYbcpkYONptX9AVa4="
}
}
}
{
"name": "yarn",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"engines": {
"npm": "5.3.0"
},
"dependencies": {
"lodash": "^4.16.4"
}
}
......@@ -57,6 +57,31 @@ testYarn() {
assertCapturedSuccess
}
testYarnCacheDirectory() {
local cache=$(mktmpdir)
local env_dir=$(mktmpdir)
local cache_dir=$(mktmpdir)
echo "${cache_dir}/yarn"> "$env_dir"/YARN_CACHE_FOLDER
compile "yarn" $cache $env_dir
# These will be created if yarn is using the directory for its cache
assertDirectoryExists ${cache_dir}/yarn
assertDirectoryExists ${cache_dir}/yarn/v1
assertDirectoryExists ${cache_dir}/yarn/v1/npm-lodash-4.16.4-01ce306b9bad1319f2a5528674f88297aeb70127
assertCapturedSuccess
}
testNpm5CacheDirectory() {
local cache=$(mktmpdir)
local env_dir=$(mktmpdir)
local cache_dir=$(mktmpdir)
echo "${cache_dir}/npm"> "$env_dir"/NPM_CONFIG_CACHE
compile "npm5" $cache $env_dir
# These will be created if npm is using the directory for its cache
assertDirectoryExists ${cache_dir}/npm
assertDirectoryExists ${cache_dir}/npm/_cacache
assertCapturedSuccess
}
testBuildWithCache() {
cache=$(mktmpdir)
......@@ -682,6 +707,7 @@ testMultiExport() {
assertCapturedSuccess
}
# Utils
pushd $(dirname 0) >/dev/null
......@@ -740,4 +766,13 @@ assertFile() {
assertEquals "$1" "$(cat ${compile_dir}/$2)"
}
assertDirectoryExists() {
if [[ ! -e "$1" ]]; then
fail "$1 does not exist"
fi
if [[ ! -d $1 ]]; then
fail "$1 is not a directory"
fi
}
source $(pwd)/test/shunit2
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