Skip to content

Commit

Permalink
Multiple lockfiles error (#1228)
Browse files Browse the repository at this point in the history
These changes build on top of [existing pnpm support](#1224) and modify the failure message shown when multiple lockfiles are detected to now include pnpm.
  • Loading branch information
colincasey committed Apr 29, 2024
1 parent 33ec0aa commit a1b9bf7
Show file tree
Hide file tree
Showing 6 changed files with 485 additions and 28 deletions.
57 changes: 33 additions & 24 deletions lib/failure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -115,53 +115,62 @@ fail_iojs_unsupported() {
}

fail_multiple_lockfiles() {
local build_dir="${1:-}"
local has_modern_lockfile=false
if [ -f "${1:-}/yarn.lock" ] || [ -f "${1:-}/package-lock.json" ]; then
has_modern_lockfile=true
fi

if [ -f "${1:-}/yarn.lock" ] && [ -f "${1:-}/package-lock.json" ]; then
mcount "failures.two-lock-files"
meta_set "failure" "two-lock-files"
declare -A lockfiles=(
["npm"]="package-lock.json"
["pnpm"]="pnpm-lock.yaml"
["Yarn"]="yarn.lock"
)

local detected_package_managers=()
for package_manager in "${!lockfiles[@]}"; do
lockfile="${lockfiles["$package_manager"]}"
if [ -f "$build_dir/$lockfile" ]; then
has_modern_lockfile=true
detected_package_managers+=("$package_manager")
fi
done

if (( "${#detected_package_managers[*]}" > 1 )); then
readarray -td '' package_managers_sorted < <(printf '%s\0' "${detected_package_managers[@]}" | sort -z --ignore-case)
mcount "failures.multiple-lock-files"
meta_set "failure" "multiple-lock-files"
header "Build failed"
warn "Two different lockfiles found: package-lock.json and yarn.lock
warn "Multiple lockfiles found
Both npm and yarn have created lockfiles for this application,
but only one can be used to install dependencies. Installing
dependencies using the wrong package manager can result in missing
Multiple package managers ($(IFS=','; printf '%s' "${package_managers_sorted[*]}")) have created lockfiles for this application,
but only one can be used to install dependencies. Installing dependencies using the wrong package manager can result in missing
packages or subtle bugs in production.
- To use npm to install your application's dependencies please delete
the yarn.lock file.
$ git rm yarn.lock
Only one of the following package manager lockfiles are supported at a time:
- ${lockfiles["npm"]}
- ${lockfiles["Yarn"]}
- ${lockfiles["pnpm"]}
- To use yarn to install your application's dependencies please delete
the package-lock.json file.
$ git rm package-lock.json
Please delete the lockfile(s) that should not be in use.
" https://help.heroku.com/0KU2EM53
fail

fi

if $has_modern_lockfile && [ -f "${1:-}/npm-shrinkwrap.json" ]; then
mcount "failures.shrinkwrap-lock-file-conflict"
meta_set "failure" "shrinkwrap-lock-file-conflict"
header "Build failed"
warn "Two different lockfiles found
warn "Multiple lockfiles conflicting with npm-shrinkwrap.json
Your application has two lockfiles defined, but only one can be used
Your application has multiple lockfiles defined which conflicts with the
shrinkwrap file you've been using. Only one lockfile can be used
to install dependencies. Installing dependencies using the wrong lockfile
can result in missing packages or subtle bugs in production.
It's most likely that you recently installed yarn which has its own
lockfile by default, which conflicts with the shrinkwrap file you've been
using.
Please make sure there is only one of the following files in your
application directory:
- yarn.lock
- pnpm-lock.yaml
- package-lock.json
- npm-shrinkwrap.json
" https://help.heroku.com/0KU2EM53
Expand Down
13 changes: 13 additions & 0 deletions test/fixtures/yarn-pnpm-and-npm-lockfiles/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions test/fixtures/yarn-pnpm-and-npm-lockfiles/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "yarn",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"lodash": "^4.16.4"
}
}
Loading

0 comments on commit a1b9bf7

Please sign in to comment.