Skip to content

Commit 1d3fc33

Browse files
authored
Dont replace npm because of lockfile if npm is already >= 5 (heroku#499)
1 parent b9adc5f commit 1d3fc33

5 files changed

Lines changed: 39 additions & 1 deletion

File tree

lib/binaries.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,11 @@ install_npm() {
6969
local version="$1"
7070
local dir="$2"
7171
local npm_lock="$3"
72+
local npm_version="$(npm --version)"
7273

73-
if $npm_lock && [ "$version" == "" ]; then
74+
# If the user has not specified a version of npm, but has an npm lockfile
75+
# upgrade them to npm 5.x if a suitable version was not installed with Node
76+
if $npm_lock && [ "$version" == "" ] && [ "${npm_version:0:1}" -lt "5" ]; then
7477
echo "Detected package-lock.json: defaulting npm to version 5.x.x"
7578
version="5.x.x"
7679
fi

test/fixtures/npm-lockfile-no-version/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@
55
"license": "MIT",
66
"dependencies": {
77
"lodash": "^4.16.4"
8+
},
9+
"engines": {
10+
"node": "8.9.1"
811
}
912
}

test/fixtures/npm-lockfile-node-6-no-version/package-lock.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "yarn",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"license": "MIT",
6+
"dependencies": {
7+
"lodash": "^4.16.4"
8+
},
9+
"engines": {
10+
"node": "6.9.5"
11+
}
12+
}

test/run

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,16 @@ testYarnLockfileOutOfDate() {
189189

190190
testDefaultToNpm5() {
191191
compile "npm-lockfile-no-version"
192+
assertCaptured "Using default npm version"
193+
assertCaptured "Installing node modules (package.json + package-lock)"
194+
assertCapturedSuccess
195+
}
196+
197+
testDefaultToNpm5WithNode6() {
198+
compile "npm-lockfile-node-6-no-version"
192199
assertCaptured "Detected package-lock.json"
193200
assertCaptured "Bootstrapping npm 5"
201+
assertCaptured "Installing node modules (package.json + package-lock)"
194202
assertCapturedSuccess
195203
}
196204

0 commit comments

Comments
 (0)