From 36d516186e30a4c97507cd19b305e5a293eca591 Mon Sep 17 00:00:00 2001 From: Josh W Lewis Date: Wed, 6 Sep 2023 10:31:49 -0500 Subject: [PATCH 1/4] Improve error messaging when attempting to install incompatible npm version --- lib/binaries.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/binaries.sh b/lib/binaries.sh index d54ec3d3..c2c2fba4 100644 --- a/lib/binaries.sh +++ b/lib/binaries.sh @@ -123,8 +123,10 @@ install_npm() { echo "npm $npm_version already installed with node" else echo "Bootstrapping npm $version (replacing $npm_version)..." - if ! npm install --unsafe-perm --quiet -g "npm@$version" 2>@1>/dev/null; then - echo "Unable to install npm $version; does it exist?" && false + if ! npm install --unsafe-perm --quiet --no-audit --no-progress -g "npm@$version" >/dev/null; then + echo "Unable to install npm $version. " \ + "Does npm $version exist? " \ + "Is npm $version compatible with this Node.js version?" && false fi # Verify npm works before capturing and ensure its stderr is inspectable later npm --version 2>&1 1>/dev/null From 6e5072786ccf847ae80a43cd8d7ed4188a3ea14d Mon Sep 17 00:00:00 2001 From: Josh W Lewis Date: Wed, 6 Sep 2023 10:32:40 -0500 Subject: [PATCH 2/4] Add changelog entry for npm error messaging improvements --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2dae9360..26d4e8a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## main +- Improved error messaging when installing an incompatible npm version. + ## v219 (2023-08-10) - Added Node.js version 16.20.2. From 439e7e45e732e99b47ca1d1afb528861df7a5c28 Mon Sep 17 00:00:00 2001 From: Josh W Lewis Date: Wed, 6 Sep 2023 10:55:12 -0500 Subject: [PATCH 3/4] Add a test around incompatible npm versions --- test/fixtures/npm-version-incompat/README.md | 1 + test/fixtures/npm-version-incompat/package.json | 13 +++++++++++++ test/run | 7 +++++++ 3 files changed, 21 insertions(+) create mode 100644 test/fixtures/npm-version-incompat/README.md create mode 100644 test/fixtures/npm-version-incompat/package.json diff --git a/test/fixtures/npm-version-incompat/README.md b/test/fixtures/npm-version-incompat/README.md new file mode 100644 index 00000000..cda334ae --- /dev/null +++ b/test/fixtures/npm-version-incompat/README.md @@ -0,0 +1 @@ +A fake README, to keep npm from polluting stderr. \ No newline at end of file diff --git a/test/fixtures/npm-version-incompat/package.json b/test/fixtures/npm-version-incompat/package.json new file mode 100644 index 00000000..d3a1bd7f --- /dev/null +++ b/test/fixtures/npm-version-incompat/package.json @@ -0,0 +1,13 @@ +{ + "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": "16.x", + "npm": "10.x" + } +} diff --git a/test/run b/test/run index f22cbd0a..b1ac482d 100755 --- a/test/run +++ b/test/run @@ -840,6 +840,13 @@ testNpmVersionSpecific() { assertCapturedSuccess } +testNpmVersionIncompatible() { + compile "npm-version-incompat" + assertCaptured "Unable to install npm 10.x" + assertCaptured "Is npm 10.x compatible with this Node.js version?" + assertCapturedError +} + testFailingBuild() { compile "failing-build" assertCaptured "Build failed" From bed042456d98276fef7c9a42a9cb3c06c503ac75 Mon Sep 17 00:00:00 2001 From: Josh W Lewis Date: Wed, 6 Sep 2023 12:55:01 -0500 Subject: [PATCH 4/4] Adjust assertion to allow stderr output --- test/run | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/run b/test/run index b1ac482d..025331a3 100755 --- a/test/run +++ b/test/run @@ -1146,7 +1146,7 @@ testNodeEnvNpmConfigProductionFalse() { assertCaptured "preinstall: production" assertCaptured "postinstall: production" assertCaptured "heroku-postbuild: production" - assertCapturedSuccess + assertEquals "Expected successful exit code" "0" "${RETURN}" } # Avoid this issue