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
ad1e2ba5
Commit
ad1e2ba5
authored
Sep 09, 2013
by
zeke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
when the default stable version doesn't satisfy, get all available versions from nodejs.org/dist
parent
89484b77
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
95 additions
and
32 deletions
+95
-32
common.sh
bin/common.sh
+6
-4
compile
bin/compile
+66
-12
test
bin/test
+11
-14
package.json
test/node-modules-caching/package.json
+11
-0
package.json
test/package-json-invalidversion/package.json
+1
-2
No files found.
bin/common.sh
View file @
ad1e2ba5
...
...
@@ -4,9 +4,9 @@
set
-e
# debug
set
-x
#
set -x
download_node
()
{
download_
and_install_
node
()
{
version
=
"
$1
"
status
"Downloading node
$version
"
...
...
@@ -33,13 +33,15 @@ query_latest_version() {
|
tail
-n1
}
all_versions
()
{
query_
all_versions
()
{
curl
-s
http://nodejs.org/dist/
\
| egrep
-o
'[0-9]+\.[0-9]+\.[0-9]+'
\
|
sort
-u
-k
1,1n
-k
2,2n
-k
3,3n
-t
.
}
function
error
()
{
error
()
{
echo
" !
$*
"
>
&2
exit
1
}
...
...
bin/compile
View file @
ad1e2ba5
...
...
@@ -2,34 +2,88 @@
build_dir
=
$1
cache_dir
=
$2
l
p_dir
=
$(
cd
$(
dirname
$0
)
;
cd
..
;
pwd
)
stable_version
=
"0.10.1
5
"
b
p_dir
=
$(
cd
$(
dirname
$0
)
;
cd
..
;
pwd
)
stable_version
=
"0.10.1
7
"
source
$
l
p_dir
/bin/common.sh
source
$
b
p_dir
/bin/common.sh
# Output debug info on exit
trap
cat_npm_debug_log EXIT
download_node
$stable_version
# cd $build_dir
status
"Downloading node
$stable_version
"
download_and_install_node
$stable_version
# Is a node version specified in package.json?
requested_version
=
$(
cat
$build_dir
/package.json | node
$lp_dir
/vendor/json engines.node 2>/dev/null
)
# echo "requested_version: $requested_version"
requested_version
=
$(
cat
$build_dir
/package.json | node
$bp_dir
/vendor/json engines.node 2>/dev/null
)
# Give a warning if no node engine is specified
if
!
test
$requested_version
;
then
echo
echo
"WARNING: No version of Node.js specified in package.json, see:"
| indent
echo
"https://devcenter.heroku.com/articles/nodejs-support#versions"
| indent
echo
fi
if
test
$requested_version
;
then
default_satisfies
=
$(
node
$lp_dir
/vendor/semver/bin/semver
$stable_version
-r
"
$requested_version
"
)
# Does the already-downloaded stable version of node satisfy the requested version?
default_satisfies
=
$(
node
$bp_dir
/vendor/semver/bin/semver
-v
$stable_version
-r
"
$requested_version
"
||
echo
""
)
if
!
test
$default_satisfies
;
then
download_node
$requested_version
status
"Using node
$stable_version
"
else
# Find all available versions from nodejs.org/dist
available_versions
=
""
for
version
in
query_all_versions
;
do
available_versions
=
"
${
available_versions
}
-v
\"
${
version
}
\"
"
done
# Determine which available versions satisfy the requested version
# https://github.com/isaacs/node-semver/blob/master/bin/semver
evaluated_versions
=
$(
node
$bp_dir
/vendor/semver/bin/semver
$available_versions
-r
"
$requested_version
"
||
echo
""
)
newest_matching_version
=
$(
"
$evaluated_versions
"
|
tail
-n
1
)
if
test
$newest_matching_version
;
then
status
"Using node
$newest_matching_version
"
download_and_install_node
$newest_matching_version
else
error
"Requested node version
${
requested_version
}
not found among available versions:
${
available_versions
}
"
fi
fi
fi
# Configure cache directories
cache_store_dir
=
"
$cache_dir
/node_modules/
$NODE_VERSION
/
$NPM_VERSION
"
cache_target_dir
=
"
$build_dir
/node_modules"
# Restore node_modules cache
if
[
-d
$cache_store_dir
]
;
then
status
"Restoring node_modules cache"
if
[
-d
$cache_target_dir
]
;
then
cp
-r
$cache_store_dir
/
*
$cache_target_dir
/
else
cp
-r
$cache_store_dir
$cache_target_dir
fi
status
"Pruning unused dependencies"
npm prune
fi
status
"Installing dependencies with npm"
npm prune
# Install dependencies
status
"Installing dependencies"
npm
install
--production
npm rebuild
echo
"Dependencies installed"
| indent
# Cache node_modules for future builds
if
[
-d
$cache_target_dir
]
;
then
status
"Caching node_modules for future builds"
rm
-rf
$cache_store_dir
mkdir
-p
$(
dirname
$cache_store_dir
)
cp
-r
$cache_target_dir
$cache_store_dir
fi
# Update the PATH
status
"Building runtime environment"
mkdir
-p
$build_dir
/.profile.d
echo
"export PATH=
\"\$
HOME/node/bin:
$HOME
/bin:
\$
HOME/node_modules/.bin:
\$
PATH
\"
"
>
$build_dir
/.profile.d/nodejs.sh
\ No newline at end of file
bin/test
View file @
ad1e2ba5
...
...
@@ -22,8 +22,7 @@ testDetectWithoutPackageJson() {
testPackageJsonWithVersion
()
{
compile
"package-json-version"
assertNotCaptured
"WARNING: No version of Node.js specified"
assertCaptured
"Using Node.js version: 0.6.11"
assertCaptured
"Using npm version: 1.1.9"
assertCaptured
"Using node 0.10.17"
assertCapturedSuccess
}
...
...
@@ -31,29 +30,27 @@ testPackageJsonWithoutVersion() {
compile
"package-json-noversion"
assertCaptured
"WARNING: No version of Node.js specified"
assertCaptured
"Using Node.js version: 0.10"
assertCaptured
"Using npm version: 1.3"
assertCapturedSuccess
}
testPackageJsonWithInvalidVersion
()
{
compile
"package-json-invalidversion"
assertCapturedError 1
"Requested engine npm version 1.1.5 does not"
}
testNothingCached
()
{
cache
=
$(
mktmpdir
)
compile
"package-json-version"
$cache
assertCapturedSuccess
assertEquals
"0"
"
$(
ls
-1
$cache
|
wc
-l
)
"
assertCapturedError 1
"Requested node version 5.0 not found"
}
testProfileCreated
()
{
compile
"package-json-version"
assertCaptured
"Building runtime environment"
assertFile
"export PATH=
\"\$
HOME/bin:
\$
HOME/node_modules/.bin:
\$
PATH
\"
"
".profile.d/nodejs.sh"
assertFile
"export PATH=
\"\$
HOME/
node/bin:
$HOME
/
bin:
\$
HOME/node_modules/.bin:
\$
PATH
\"
"
".profile.d/nodejs.sh"
assertCapturedSuccess
}
testNodeModulesCached
()
{
cache
=
$(
mktmpdir
)
compile
"node-modules-caching"
$cache
assertEquals
"1"
"
$(
ls
-1
$cache
/node_modules/0.10.15/1.3.5 |
wc
-l
)
"
}
## utils ########################################
pushd
$(
dirname
0
)
>
/dev/null
...
...
@@ -78,7 +75,7 @@ COMPILE_DIR=""
compile
()
{
COMPILE_DIR
=
$(
mktmpdir
)
cp
-r
${
BASE
}
/test/
$1
/
*
${
COMPILE_DIR
}
/
capture
${
BASE
}
/bin/compile
${
COMPILE_DIR
}
$
2
capture
${
BASE
}
/bin/compile
${
COMPILE_DIR
}
$
{
2
:-$(
mktmpdir
)}
}
assertFile
()
{
...
...
test/node-modules-caching/package.json
0 → 100644
View file @
ad1e2ba5
{
"name"
:
"myapp"
,
"version"
:
"0.0.1"
,
"engines"
:
{
"node"
:
"0.10.15"
,
"npm"
:
"1.3.5"
},
"dependencies"
:
{
"express"
:
"latest"
}
}
\ No newline at end of file
test/package-json-invalidversion/package.json
View file @
ad1e2ba5
...
...
@@ -3,7 +3,6 @@
"version"
:
"0.0.1"
,
"engines"
:
{
"node"
:
"0.6.11"
,
"npm"
:
"1.1.5"
"node"
:
"5.0"
}
}
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