Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
H
heroku-buildpack-nodejs
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Python-Dev
heroku-buildpack-nodejs
Commits
40214da8
Commit
40214da8
authored
Mar 23, 2015
by
Hunter Loftis
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #203 from hone/user_caching
allow users to cache their own directories
parents
c8cb21e7
e479aae5
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
112 additions
and
15 deletions
+112
-15
build.sh
lib/build.sh
+72
-15
README.md
test/fixtures/cache-directories/README.md
+1
-0
bower.json
test/fixtures/cache-directories/bower.json
+6
-0
package.json
test/fixtures/cache-directories/package.json
+19
-0
run
test/run
+14
-0
No files found.
lib/build.sh
View file @
40214da8
...
...
@@ -164,6 +164,8 @@ install_npm() {
}
function
build_dependencies
()
{
restore_cache
if
[
"
$modules_source
"
==
""
]
;
then
info
"Skipping dependencies (no source for node_modules)"
...
...
@@ -174,21 +176,8 @@ function build_dependencies() {
npm
install
--unsafe-perm
--quiet
--userconfig
$build_dir
/.npmrc 2>&1 | indent
else
cache_status
=
$(
get_cache_status
)
if
[
"
$cache_status
"
==
"valid"
]
;
then
info
"Restoring node modules from cache"
cp
-r
$cache_dir
/node/node_modules
$build_dir
/
info
"Pruning unused dependencies"
npm
--unsafe-perm
prune 2>&1 | indent
info
"Installing any new modules"
npm
install
--unsafe-perm
--quiet
--userconfig
$build_dir
/.npmrc 2>&1 | indent
else
info
"
$cache_status
"
info
"Installing node modules"
touch
$build_dir
/.npmrc
npm
install
--unsafe-perm
--quiet
--userconfig
$build_dir
/.npmrc 2>&1 | indent
fi
info
"Installing node modules"
npm
install
--unsafe-perm
--quiet
--userconfig
$build_dir
/.npmrc 2>&1 | indent
fi
}
...
...
@@ -242,6 +231,7 @@ create_cache() {
if
test
-d
$build_dir
/node_modules
;
then
cp
-r
$build_dir
/node_modules
$cache_dir
/node
fi
write_user_cache
}
clean_cache
()
{
...
...
@@ -267,3 +257,70 @@ get_cache_status() {
echo
"valid"
fi
}
restore_cache
()
{
local
directories
=(
$(
cache_directories
)
)
local
cache_status
=
$(
get_cache_status
)
if
[
"
$directories
"
!=
-1
]
;
then
info
"Restoring
${#
directories
[@]
}
directories from cache:"
for
directory
in
"
${
directories
[@]
}
"
do
local
source_dir
=
"
$cache_dir
/node/
$directory
"
if
[
-e
$source_dir
]
;
then
if
[
"
$directory
"
==
"node_modules"
]
;
then
restore_npm_cache
else
info
"-
$directory
"
cp
-r
$source_dir
$build_dir
/
fi
fi
done
elif
[
"
$cache_status
"
==
"valid"
]
;
then
restore_npm_cache
info
"
$cache_status
"
else
touch
$build_dir
/.npmrc
fi
}
restore_npm_cache
()
{
info
"Restoring node modules from cache"
cp
-r
$cache_dir
/node/node_modules
$build_dir
/
info
"Pruning unused dependencies"
npm
--unsafe-perm
prune 2>&1 | indent
}
cache_directories
()
{
local
package_json
=
"
$build_dir
/package.json"
local
key
=
".cache_directories"
local
check
=
$(
key_exist
$package_json
$key
)
local
result
=
-1
if
[
"
$check
"
!=
-1
]
;
then
result
=
$(
read_json
"
$package_json
"
"
$key
[]"
)
fi
echo
$result
}
key_exist
()
{
local
file
=
$1
local
key
=
$2
local
output
=
$(
read_json
$file
$key
)
if
[
-n
"
$output
"
]
;
then
echo
1
else
echo
-1
fi
}
write_user_cache
()
{
local
directories
=(
$(
cache_directories
)
)
if
[
"
$directories
"
!=
-1
]
;
then
info
"Storing directories:"
for
directory
in
"
${
directories
[@]
}
"
do
info
"-
$directory
"
cp
-r
$build_dir
/
$directory
$cache_dir
/node/
done
fi
}
test/fixtures/cache-directories/README.md
0 → 100644
View file @
40214da8
A fake README, to keep npm from polluting stderr.
\ No newline at end of file
test/fixtures/cache-directories/bower.json
0 → 100644
View file @
40214da8
{
"name"
:
"node-buildpack-test-app"
,
"dependencies"
:
{
"jquery"
:
"^1.11.1"
}
}
test/fixtures/cache-directories/package.json
0 → 100644
View file @
40214da8
{
"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"
},
"engines"
:
{
"node"
:
"0.10.18"
},
"dependencies"
:
{
"bower"
:
"1.3.12"
},
"scripts"
:
{
"postinstall"
:
"bower install --allow-root"
},
"cache_directories"
:
[
"bower_components"
,
"node_modules"
]
}
test/run
View file @
40214da8
...
...
@@ -172,6 +172,20 @@ testBuildWithCache() {
assertCapturedSuccess
}
testBuildWithUserCacheDirectories
()
{
cache
=
$(
mktmpdir
)
compile
"cache-directories"
$cache
assertCapturedSuccess
assertEquals
"1"
"
$(
ls
-1
$cache
/node |
grep
bower_components |
wc
-l
)
"
assertEquals
"1"
"
$(
ls
-1
$cache
/node |
grep
node_modules |
wc
-l
)
"
compile
"cache-directories"
$cache
assertCaptured
"Restoring 2 directories from cache:"
assertCaptured
"- bower_components"
assertCaptured
"Restoring node modules from cache"
assertCapturedSuccess
}
testModulesCheckedIn
()
{
compile
"modules-checked-in"
assertCaptured
"node_modules source: prebuilt"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment