Skip to content

Commit

Permalink
Merge pull request #746 from heroku/da/detect-yarn2
Browse files Browse the repository at this point in the history
Detect Yarn2 and give error message
  • Loading branch information
danielleadams authored Mar 25, 2020
2 parents 984a731 + 333fac6 commit 30cedcb
Show file tree
Hide file tree
Showing 16 changed files with 14,702 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- Bump rake from 12.3.1 to 12.3.3 ([#742](https://github.com/heroku/heroku-buildpack-nodejs/pull/742))
- Upgrade Go to 1.14 ([#744](https://github.com/heroku/heroku-buildpack-nodejs/pull/744))
- Bump `npm ci` usage for installing dependencies to 20% ([#745](https://github.com/heroku/heroku-buildpack-nodejs/pull/745))
- Detect Yarn 2 usage, produce error message, and fail build (until supported) ([#746](https://github.com/heroku/heroku-buildpack-nodejs/pull/746))

## v167 (2020-02-06)
- Make minor upgrades to gems ([#735](https://github.com/heroku/heroku-buildpack-nodejs/pull/735))
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Having trouble? Dig it? Feature request?
For local development, you may need the following tools:

- [Docker](https://hub.docker.com/search?type=edition&offering=community)
- [Go 1.14]((https://golang.org/doc/install#install))
- [Go 1.14](https://golang.org/doc/install#install)
- [upx](https://upx.github.io/)

### Deploying an app with a fork or branch
Expand Down
7 changes: 5 additions & 2 deletions bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ source "$BP_DIR/lib/metadata.sh"
source "$BP_DIR/lib/features.sh"
# shellcheck source=lib/builddata.sh
source "$BP_DIR/lib/builddata.sh"
# shellcheck source=lib/yarn2.sh
source "$BP_DIR/lib/yarn2.sh"

export PATH="$BUILD_DIR/.heroku/node/bin:$BUILD_DIR/.heroku/yarn/bin":$PATH

Expand Down Expand Up @@ -85,7 +87,7 @@ trap 'handle_failure' ERR
meta_init "$CACHE_DIR"
# Make sure that it's empty and save any previous build's data
meta_setup
# the "build-step" key keeps track of where we are in the execution
# the "build-step" key keeps track of where we are in the execution
# so that we can see where failed builds errored
meta_set "build-step" "init"

Expand All @@ -99,14 +101,15 @@ meta_set "build-step" "init"
features_init "nodejs" "$BUILD_DIR" "$CACHE_DIR" "$BP_DIR/features"
log_initial_state
generate_uuids

### Failures that should be caught immediately

fail_dot_heroku "$BUILD_DIR"
fail_dot_heroku_node "$BUILD_DIR"
fail_invalid_package_json "$BUILD_DIR"
fail_multiple_lockfiles "$BUILD_DIR"
fail_iojs_unsupported "$BUILD_DIR"
fail_yarn2_unsupported "$YARN" "$BUILD_DIR"
warn_prebuilt_modules "$BUILD_DIR"
warn_missing_package_json "$BUILD_DIR"

Expand Down
Binary file added etc/vendor/yq-darwin
Binary file not shown.
Binary file added etc/vendor/yq-linux
Binary file not shown.
30 changes: 28 additions & 2 deletions lib/failure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,43 @@ fail_iojs_unsupported() {
}
io.js merged back into Nodejs.org in 2015 and has been unsupported
for many years. It is likely to contain several large security
for many years. It is likely to contain several large security
vulnerabilities that have been patched in Node.
You can update your app to use the official Node.js release by
You can update your app to use the official Node.js release by
removing the version specfication under \"engines\" in your
package.json.
"
fail
fi
}

fail_yarn2_unsupported() {
local uses_yarn="$1"
local build_dir="$2"
local uses_yarn2

uses_yarn2=$(detect_yarn2 "$uses_yarn" "$build_dir")

if [[ "$uses_yarn2" == "true" ]]; then
mcount "failures.yarn2-unsupported"
meta_set "failure" "yarn2-unsupported"
warn "
Thanks for trying Heroku with Yarn 2!
We are busy working to support Yarn 2, but it's not quite there yet.
Thanks for your patience while we work to give full support to
all of our Yarn users.
To use Yarn 1, set the local environment to use Yarn 1 and regenerate the
yarn.lock file for this app. When checking in the regenerated lockfile,
remember to remove files that have been generated by Yarn 2, which may
include yarnrc.yml, .yarn directory, pnp.js.
"
fail
fi
}

fail_multiple_lockfiles() {
local has_modern_lockfile=false
if [ -f "${1:-}/yarn.lock" ] || [ -f "${1:-}/package-lock.json" ]; then
Expand Down
21 changes: 21 additions & 0 deletions lib/yarn2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

YQ="$BP_DIR/etc/vendor/yq-$(get_os)"

detect_yarn2() {
local uses_yarn="$1"
local build_dir="$2"
local yml_metadata
local version

yml_metadata=$($YQ r "$build_dir/yarn.lock" __metadata 2>&1)

# grep for version in case the output is a parsing error
version=$(echo "$yml_metadata" | grep version)

if [[ "$uses_yarn" == "true" && "$version" != "" ]]; then
echo "true"
else
echo "false"
fi
}
15 changes: 15 additions & 0 deletions test/fixtures/yarn-2-without-cache/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "yarn-2-without-cache",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"engines": {
"yarn": "1.x"
},
"dependencies": {
"lodash": "^4.16.4"
},
"devDependencies": {
"debug": "^4.1.1"
}
}
37 changes: 37 additions & 0 deletions test/fixtures/yarn-2-without-cache/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# This file is generated by running "yarn install" inside your project.
# Manual changes might be lost - proceed with caution!

__metadata:
version: 4

"debug@npm:^4.1.1":
version: 4.1.1
resolution: "debug@npm:4.1.1"
dependencies:
ms: ^2.1.1
checksum: e3bfa1544ced80ac5764aa313530150af442e5ce53f91090f00e3aff33a8b535ce60a7502d1451b3cbc2b9cd6994b3a08a38fbd3ff7a2ec801ad79d8b457b8e8
languageName: node
linkType: hard

"lodash@npm:^4.16.4":
version: 4.17.15
resolution: "lodash@npm:4.17.15"
checksum: b018ec8d4c95f14a4b57005a247eca1bc25639322939471a1958d3bc721b4f18e90edb6ea564854593a8bc1f94956a0352cf0cd372991b98c42d61c0cd11e5a3
languageName: node
linkType: hard

"ms@npm:^2.1.1":
version: 2.1.2
resolution: "ms@npm:2.1.2"
checksum: 2a3d955e5199024d4b18630ff47c21b52703a5e892615ae233486b8108f26b5493736009754263eebae765ab79d6e20327dad6e52d7843b689d404245e286549
languageName: node
linkType: hard

"yarn-2-without-cache@workspace:.":
version: 0.0.0-use.local
resolution: "yarn-2-without-cache@workspace:."
dependencies:
debug: ^4.1.1
lodash: ^4.16.4
languageName: unknown
linkType: soft
Loading

0 comments on commit 30cedcb

Please sign in to comment.