-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Support Yarn 2 #795
Changes from 69 commits
8619387
4dd7470
d870aae
7c1753b
7e39e40
084e896
5ceee45
fe3970a
5e3d420
b21c3bd
143d15c
64cd721
5e602ea
782083f
713c1fe
24450e7
1fd97ff
97ed3e1
9d18994
f458273
6d5d13c
9ef8adb
ef14414
aa23ed2
d318817
990a97f
f3140ae
bf5af07
fb72c43
78b386f
a2a314c
fc5c211
4446173
6ec3552
e5b5e8c
9b431ed
7a40372
558b452
b70e692
9b2aea7
6f6d0ec
856163f
7b5e98c
dbf9343
0a07ff9
0cfa519
7367eb4
be32a92
c1a9d53
1a6bce1
28c290d
3f7d8af
00843ee
25c67c2
3856188
e10b7b5
da0b5e8
fe1f794
ce944fb
e2a30fe
af835e7
b06c6ae
13c6c17
cef62af
97a933e
d4700de
18d0f65
f46062e
7efa680
2825b0c
898e46e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,6 +97,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" | ||
|
@@ -110,7 +111,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" | ||
|
||
|
@@ -141,6 +141,38 @@ 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. | ||
" | ||
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 | ||
|
||
if [[ $(features_get "cache-native-yarn-cache") == "false" ]]; then | ||
warn "You're currently using the heroku-buildpack-features file to configure. Using Yarn Cache has moved behind an environment variable. Use 'heroku config:set USE_YARN_CACHE=false' to set the variable." | ||
USE_YARN_CACHE=false | ||
|
@@ -153,6 +185,10 @@ install_bins() { | |
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" | ||
|
@@ -193,6 +229,10 @@ install_bins() { | |
fi | ||
|
||
warn_old_npm | ||
|
||
if [[ $YARN2 == true ]]; then | ||
YARN=false | ||
fi | ||
} | ||
|
||
header "Installing binaries" | output "$LOG_FILE" | ||
|
@@ -253,8 +293,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." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)" | ||
|
@@ -309,7 +350,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" ]] && [[ "$USE_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" ]] && [[ "$USE_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" | ||
|
There was a problem hiding this comment.
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 thenode-modules
linker https://yarnpkg.com/configuration/yarnrc#nodeLinkerThough it would be faster to cache the actual cache folder which you can get using
yarn config get cacheFolder
There was a problem hiding this comment.
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.