Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Yarn 2 #795

Merged
merged 71 commits into from
Jul 14, 2020
Merged
Show file tree
Hide file tree
Changes from 66 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
8619387
remove yarn 2 failure message; add feature list under CHANGELOG
Apr 7, 2020
4dd7470
create warning when yarn 2 is used with NODE_MODULES_CACHE
lillianzhang331 Apr 8, 2020
d870aae
remove date in changelog and case error in test
lillianzhang331 Apr 8, 2020
7c1753b
Merge pull request #757 from heroku/warn-yarn2-with-cache
lillianzhang331 Apr 15, 2020
7e39e40
warning when yarn 2 and engine package.json
lillianzhang331 Apr 20, 2020
084e896
update changelog
lillianzhang331 Apr 20, 2020
5ceee45
Merge branch 'feature/yarn2-support' into warn-yarn2-engine-package
lillianzhang331 Apr 20, 2020
fe3970a
check for if engine is set
lillianzhang331 Apr 21, 2020
5e3d420
Merge branch 'warn-yarn2-engine-package' of https://github.com/heroku…
lillianzhang331 Apr 21, 2020
b21c3bd
create separate fixture for testing
lillianzhang331 Apr 22, 2020
143d15c
Merge pull request #761 from heroku/warn-yarn2-engine-package
lillianzhang331 Apr 22, 2020
64cd721
display warning for if .npmrc exists
lillianzhang331 Apr 22, 2020
5e602ea
update changelog
lillianzhang331 Apr 22, 2020
782083f
syntax
lillianzhang331 Apr 22, 2020
713c1fe
spellcheck
lillianzhang331 Apr 22, 2020
24450e7
display warning for when .yarnrc file exists
lillianzhang331 Apr 23, 2020
1fd97ff
update changelog
lillianzhang331 Apr 23, 2020
97ed3e1
Merge pull request #768 from heroku/warn-yarnrc
lillianzhang331 Apr 24, 2020
9d18994
Merge branch 'feature/yarn2-support' into warn-npmrc
lillianzhang331 Apr 24, 2020
f458273
Merge pull request #764 from heroku/warn-npmrc
lillianzhang331 Apr 24, 2020
6d5d13c
add checks for yarn 2 that look for yarnrc.yml, yarnPath, and .yarn/r…
Apr 16, 2020
9ef8adb
add yarn artifacts for engine repo
Apr 23, 2020
ef14414
update CHANGELOG
Apr 27, 2020
aa23ed2
move failures into first yarn 2 if block
Apr 27, 2020
d318817
clean up the failure messages
Apr 27, 2020
990a97f
Merge pull request #759 from heroku/da/detect-yarn-vendor
danielleadams Apr 29, 2020
f3140ae
remove yarn 2 failure message; add feature list under CHANGELOG
Apr 7, 2020
bf5af07
create warning when yarn 2 is used with NODE_MODULES_CACHE
lillianzhang331 Apr 8, 2020
fb72c43
remove date in changelog and case error in test
lillianzhang331 Apr 8, 2020
78b386f
warning when yarn 2 and engine package.json
lillianzhang331 Apr 20, 2020
a2a314c
update changelog
lillianzhang331 Apr 20, 2020
fc5c211
check for if engine is set
lillianzhang331 Apr 21, 2020
4446173
create separate fixture for testing
lillianzhang331 Apr 22, 2020
6ec3552
display warning for if .npmrc exists
lillianzhang331 Apr 22, 2020
e5b5e8c
update changelog
lillianzhang331 Apr 22, 2020
9b431ed
syntax
lillianzhang331 Apr 22, 2020
7a40372
spellcheck
lillianzhang331 Apr 22, 2020
558b452
display warning for when .yarnrc file exists
lillianzhang331 Apr 23, 2020
b70e692
update changelog
lillianzhang331 Apr 23, 2020
9b2aea7
add checks for yarn 2 that look for yarnrc.yml, yarnPath, and .yarn/r…
Apr 16, 2020
6f6d0ec
add yarn artifacts for engine repo
Apr 23, 2020
856163f
move failures into first yarn 2 if block
Apr 27, 2020
7b5e98c
clean up the failure messages
Apr 27, 2020
dbf9343
Merge branch 'feature/yarn2-support' of https://github.com/heroku/her…
lillianzhang331 May 4, 2020
0a07ff9
add vendored alias for yarn
lillianzhang331 May 4, 2020
0cfa519
turn production and ignore-script flags off for yarn 2
lillianzhang331 May 5, 2020
7367eb4
update changelog
lillianzhang331 May 5, 2020
be32a92
shellcheck
lillianzhang331 May 5, 2020
c1a9d53
update successful tests and edit readme for debugging
lillianzhang331 May 6, 2020
1a6bce1
escaping for shellcheck
lillianzhang331 May 6, 2020
28c290d
add std_out info to readme
lillianzhang331 May 6, 2020
3f7d8af
Merge pull request #775 from heroku/add-global-yarn
lillianzhang331 May 7, 2020
00843ee
set $YARN to false when $YARN2 is true
May 5, 2020
25c67c2
update CHANGELOG
May 5, 2020
3856188
update tests to capture successes when buildpack uses Yarn 2
May 5, 2020
e10b7b5
add Yarn artifacts to test fixtures for warning (non failing) builds
May 5, 2020
da0b5e8
Merge pull request #776 from heroku/da/yarn2-turns-YARN-false
danielleadams May 7, 2020
fe1f794
skippef writing to cache and pruning with yarn 2
lillianzhang331 May 12, 2020
ce944fb
update changelog
lillianzhang331 May 12, 2020
e2a30fe
separate if statement for yarn 2 and consistent wording
lillianzhang331 May 13, 2020
af835e7
Merge pull request #785 from heroku/skip-yarn2-cache-prune
lillianzhang331 May 14, 2020
b06c6ae
update yarn version for vendor package; add tests to test installed p…
May 20, 2020
13c6c17
update CHANGELOG
May 20, 2020
cef62af
regenerate install-state.gz
May 20, 2020
97a933e
use installed yarn to reference yarn package
Jun 2, 2020
d4700de
Merge pull request #786 from heroku/test-installed-packages
danielleadams Jun 5, 2020
18d0f65
merge master to feature branch
Jun 26, 2020
f46062e
merge master to feature branch
Jul 13, 2020
7efa680
update CHANGELOG
Jul 13, 2020
2825b0c
add an link to Yarn install docs
Jul 13, 2020
898e46e
fix typo in the CHANGELOG
Jul 14, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Node.js Buildpack Changelog

## feature: Yarn 2 support
- Add warning for detection of Yarn 2 usage with caching ([#755](https://github.com/heroku/heroku-buildpack-nodejs/pull/755))
- Add warning for Yarn 2 usage, warn user of ignoring engine from package.json ([#761](https://github.com/heroku/heroku-buildpack-nodejs/pull/761))
- Add warning for if .npmrc file exists when using Yarn 2 ([#764](https://github.com/heroku/heroku-buildpack-nodejs/pull/764))
- Add warning for if .yarnrc file exists when using Yarn 2 ([#768](https://github.com/heroku/heroku-buildpack-nodejs/pull/768))
- Add checks for Yarn 2 ([#759](https://github.com/heroku/heroku-buildpack-nodejs/pull/759))
- Turn off production and ignore-script flags for Yarn 2 and add global vendored yarn alias ([775] (https://github.com/heroku/heroku-buildpack-nodejs/pull/775))
- Set `$YARN` to false when `$YARN2` is true ([#776](https://github.com/heroku/heroku-buildpack-nodejs/pull/776))
- Skip writing to the cache and pruning of the node modules when Yarn 2 is used ([#785](https://github.com/heroku/heroku-buildpack-nodejs/pull/785))
- Test use of packages in `.yarn/release` directory ([#786](https://github.com/heroku/heroku-buildpack-nodejs/pull/786))

## master
- display yarn engine log to build output when engine is provided in monorepo ([#771](https://github.com/heroku/heroku-buildpack-nodejs/pull/771))

Expand Down
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,36 @@ The tests are run via the vendored
[shunit2](https://github.com/kward/shunit2)
test framework.

### Debugging

To display the logged build outputs to assist with debugging, use the "echo" and "cat" commands. For example:

```
test() {
local log_file var

var="testtest"
log_file=$(mktemp)
echo "this is the log file" > "$log_file"
echo "test log file" >> "$log_file"

# use `echo` and `cat` for printing variables and reading files respectively
echo $var
cat $log_file

# some cases when debugging is necessary
assertEquals "$var" "testtest"
assertFileContains "test log file" "$log_file"
}
```
Running the test above would produce:
```
testtest
this is the log file
test log file
```
The test output writes to STD_OUT. Use `cat $STD_OUT` to read.

## Common Issues

### Proxy Issues
Expand Down
53 changes: 49 additions & 4 deletions bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ meta_set "build-step" "init"
[ -e "$BUILD_DIR/node_modules" ] && PREBUILD=true || PREBUILD=false
[ -f "$BUILD_DIR/yarn.lock" ] && YARN=true || YARN=false
[ -f "$BUILD_DIR/package-lock.json" ] && NPM_LOCK=true || NPM_LOCK=false
YARN2=$(detect_yarn2 "$YARN" "$BUILD_DIR")

### Save build info
features_init "nodejs" "$BUILD_DIR" "$CACHE_DIR" "$BP_DIR/features"
Expand All @@ -109,7 +110,6 @@ 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 Expand Up @@ -140,13 +140,49 @@ create_build_env
[ ! "$NPM_CONFIG_CACHE" ] && NPM_CONFIG_CACHE=$(mktemp -d -t npmcache.XXXXX)
export YARN_CACHE_FOLDER NPM_CONFIG_CACHE

### Configure vendored package manager
export YARN2_PATH

if [[ "$YARN2" == "true" ]]; then
if [[ "$NODE_MODULES_CACHE" == "true" ]]; then
warn "
WARNING- You are using Yarn 2. The buildpack won't cache, because Yarn 2 does not provide node modules.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does provide a node_modules folder with the node-modules linker https://yarnpkg.com/configuration/yarnrc#nodeLinker

Though it would be faster to cache the actual cache folder which you can get using yarn config get cacheFolder

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This warning message should be reworded - so thanks for pointing this out. However, we're not supporting this yet in this first phase.

"
fi

if [[ -f "$BUILD_DIR/.npmrc" ]]; then
warn "There is an existing .npmrc file that will not be used. All configurations are read from the .yarnrc.yml file."
fi

if [[ -f "$BUILD_DIR/.yarnrc" ]]; then
warn "There is an existing .yarnrc file that will not be used. All configurations are read from the .yarnrc.yml file."
fi

### Configure Yarn 2
# fail for no yarnrc.yml
fail_missing_yarnrc_yml "$BUILD_DIR"

# get yarn_path
YARN2_PATH=$(get_yarn_path "$BUILD_DIR")

# fail for no yarnPath in rc
fail_missing_yarn_path "$BUILD_DIR" "$YARN2_PATH"

# fail for missing yarn in .yarn/releases
fail_missing_yarn_vendor "$BUILD_DIR" "$YARN2_PATH"
fi

install_bins() {
local node_engine npm_engine yarn_engine npm_version node_version

node_engine=$(read_json "$BUILD_DIR/package.json" ".engines.node")
npm_engine=$(read_json "$BUILD_DIR/package.json" ".engines.npm")
yarn_engine=$(read_json "$BUILD_DIR/package.json" ".engines.yarn")

if [[ "$YARN2" == "true" && -n "$yarn_engine" ]]; then
warn "You should be using a vendored version of Yarn. Heroku will ignore the engine from the package.json."
fi

meta_set "node-version-request" "$node_engine"
meta_set "npm-version-request" "$npm_engine"
meta_set "yarn-version-request" "$yarn_engine"
Expand Down Expand Up @@ -187,6 +223,10 @@ install_bins() {
fi

warn_old_npm

if [[ $YARN2 == true ]]; then
YARN=false
fi
}

header "Installing binaries" | output "$LOG_FILE"
Expand Down Expand Up @@ -247,8 +287,9 @@ build_dependencies() {

cache_status="$(get_cache_status "$CACHE_DIR")"
start=$(nowms)

if $YARN; then
if [[ "$YARN2" == "true" ]]; then
echo "Using Yarn 2, skipping installations."
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yarn install would still need to run for dependencies with a postinstall script when using PnP and to create the node_modules folder when using the node-modules linker

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right - thanks for pointing this out. The assumption is that the install scripts will not be run for now since install is not run. I made a note in the PR description. We will eventually want to support this, of course, but not in this first draft.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, keep in mind any dependency with a postinstall script wont work. So for example core-js wont be found

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we'll be working on that and keep that in mind. This is a priority. Thanks for the review!

elif $YARN; then
yarn_node_modules "$BUILD_DIR"
elif $PREBUILD; then
echo "Prebuild detected (node_modules already exists)"
Expand Down Expand Up @@ -303,7 +344,11 @@ prune_devdependencies() {
# and in the new feature
# and we're using the default cache directories
# then save off the cache after we prune out devDepenencies
if [[ "$YARN" == "true" ]] && [[ $(features_get "cache-native-yarn-cache") == "true" ]] && [[ "$(get_cache_directories "$BUILD_DIR")" == "" ]]; then
if [[ "$YARN2" == "true" ]]; then
echo "Using Yarn 2, writing to the cache and pruning of the node modules will be skipped." | output "$LOG_FILE"
meta_set "build-step" "prune-dependencies"
meta_set "build-step" "save-cache"
elif [[ "$YARN" == "true" ]] && [[ $(features_get "cache-native-yarn-cache") == "true" ]] && [[ "$(get_cache_directories "$BUILD_DIR")" == "" ]]; then
meta_set "build-step" "prune-dependencies"
header "Pruning devDependencies" | output "$LOG_FILE"
prune_devdependencies | output "$LOG_FILE"
Expand Down
7 changes: 6 additions & 1 deletion lib/binaries.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ install_yarn() {
tar xzf /tmp/yarn.tar.gz -C "$dir" --strip 1
fi
chmod +x "$dir"/bin/*
echo "Installed yarn $(yarn --version)"

if $YARN2; then
echo "Using yarn $(yarn --version)"
else
echo "Installed yarn $(yarn --version)"
fi
}

install_nodejs() {
Expand Down
8 changes: 4 additions & 4 deletions lib/dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ run_if_present() {
script=$(read_json "$build_dir/package.json" ".scripts[\"$script_name\"]")

if [[ "$has_script_name" == "true" ]]; then
if $YARN; then
if $YARN || $YARN2; then
echo "Running $script_name (yarn)"
# yarn will throw an error if the script is an empty string, so check for this case
if [[ -n "$script" ]]; then
Expand Down Expand Up @@ -92,7 +92,7 @@ yarn_node_modules() {
}

yarn_prune_devdependencies() {
local build_dir=${1:-}
local build_dir=${1:-}

if [ "$NODE_ENV" == "test" ]; then
echo "Skipping because NODE_ENV is 'test'"
Expand All @@ -106,7 +106,7 @@ yarn_prune_devdependencies() {
echo "Skipping because YARN_PRODUCTION is '$YARN_PRODUCTION'"
meta_set "skipped-prune" "true"
return 0
else
else
cd "$build_dir" || return
monitor "yarn-prune" yarn install --frozen-lockfile --ignore-engines --ignore-scripts --prefer-offline 2>&1
meta_set "skipped-prune" "false"
Expand Down Expand Up @@ -180,7 +180,7 @@ npm_rebuild() {

npm_prune_devdependencies() {
local npm_version
local build_dir=${1:-}
local build_dir=${1:-}

npm_version=$(npm --version)

Expand Down
78 changes: 73 additions & 5 deletions lib/failure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,7 @@ fail_iojs_unsupported() {
}

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

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

if [[ "$uses_yarn2" == "true" ]]; then
mcount "failures.yarn2-unsupported"
Expand Down Expand Up @@ -365,6 +361,78 @@ fail_invalid_semver() {
fi
}

# Yarn 2 failures

fail_missing_yarnrc_yml() {
local build_dir="$1"

if [[ ! -f "$build_dir/.yarnrc.yml" ]]; then
mcount "failures.missing-yarnrc-yml"
meta_set "failure" "missing-yarnrc-yml"
header "Build failed"
warn "The 'yarnrc.yml' file is not found

It looks like the 'yarnrc.yml' file is missing from this project. Please
make sure this file is checked into version control and made available to
Heroku.

To generate 'yarnrc.yml', make sure Yarn 2 is installed on your local
machine and set the version in your project directory with:

$ yarn set version berry
"
fail
fi
}

fail_missing_yarn_path() {
local build_dir="$1"
local yarn_path="$2"

if [[ "$yarn_path" == "" ]]; then
mcount "failures.missing-yarn-path"
meta_set "failure" "missing-yarn-path"
header "Build failed"
warn "The 'yarnPath' could not be read from the 'yarnrc.yml' file

It looks like 'yarnrc.yml' is missing the 'yarnPath' value, which is needed
to identify the location of yarn for this build.

To regenerate 'yarnrc.yml' with the 'yarnPath' value set, make sure Yarn 2
is installed on your local machine and set the version in your project
directory with:

$ yarn set version berry
"
fail
fi
}

fail_missing_yarn_vendor() {
local build_dir="$1"
local yarn_path="$2"

if [[ ! -f "$build_dir/$yarn_path" ]]; then
mcount "failures.missing-yarn-vendor"
meta_set "failure" "missing-yarn-vendor"
header "Build failed"
warn "Yarn was not found

It looks like yarn is missing from $yarn_path, which is needed to continue
this build on Heroku. Yarn 2 recommends vendoring Yarn under the '.yarn/releases'
directory, so remember to check the '.yarn' directory into version control
to use during builds.

To generate the '.yarn' directory correctly, make sure Yarn 2 is installed
on your local machine and run the following in your project directory:

$ yarn install
$ yarn set version berry
"
fail
fi
}

log_other_failures() {
local log_file="$1"
if grep -qi "sh: 1: .*: not found" "$log_file"; then
Expand Down
5 changes: 5 additions & 0 deletions lib/yarn2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ detect_yarn2() {
echo "false"
fi
}

get_yarn_path() {
local build_dir="$1"
$YQ r "$build_dir/.yarnrc.yml" yarnPath 2>&1
}
Loading