Skip to content

Commit

Permalink
Multiple lockfiles error
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 2, 2024
1 parent a25345b commit b903149
Show file tree
Hide file tree
Showing 6 changed files with 491 additions and 23 deletions.
58 changes: 39 additions & 19 deletions lib/failure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -115,31 +115,53 @@ 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,
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.
the pnpm and/or Yarn file.
$ git rm yarn.lock
$ git rm ${lockfiles["pnpm"]}
$ git rm ${lockfiles["Yarn"]}
- To use yarn to install your application's dependencies please delete
the package-lock.json file.
- To use Yarn to install your application's dependencies please delete
the npm and/or pnpm lockfiles.
$ git rm package-lock.json
$ git rm ${lockfiles["npm"]}
$ git rm ${lockfiles["pnpm"]}
- To use pnpm to install your application's dependencies please delete
the npm and/or Yarn lockfiles.
$ git rm ${lockfiles["npm"]}
$ git rm ${lockfiles["Yarn"]}
" https://help.heroku.com/0KU2EM53
fail
fi
Expand All @@ -148,20 +170,18 @@ fail_multiple_lockfiles() {
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 b903149

Please sign in to comment.