Skip to content

Commit

Permalink
Manually applied compile patches
Browse files Browse the repository at this point in the history
  • Loading branch information
simar0at committed Jun 20, 2024
1 parent b1e0bfc commit 641604a
Showing 1 changed file with 87 additions and 21 deletions.
108 changes: 87 additions & 21 deletions bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ source "$BP_DIR/lib/yarn-2.sh"

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

export COREPACK_HOME="$BUILD_DIR/.heroku/corepack"

LOG_FILE=$(mktemp -t node-build-log.XXXXX)
echo "" > "$LOG_FILE"

Expand Down Expand Up @@ -102,6 +104,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
[ -f "$BUILD_DIR/pnpm-lock.yaml" ] && PNPM=true || PNPM=false
YARN_2=$(detect_yarn_2 "$YARN" "$BUILD_DIR")

### Save build info
Expand Down Expand Up @@ -183,24 +186,30 @@ if [[ "$YARN_2" == "true" ]]; then
# get yarn_path
VENDOR_PATH=$(get_yarn_path "$BUILD_DIR")

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

# fail for missing yarn in .yarn/releases
fail_missing_yarn_vendor "$BUILD_DIR" "$VENDOR_PATH"
# if we're installing yarn via corepack we don't need to fail
# on the yarn path configuration or vendored script
if [[ "$(read_json "$BUILD_DIR/package.json" ".packageManager")" != yarn* ]]; then
# fail for no yarnPath in rc
fail_missing_yarn_path "$BUILD_DIR" "$VENDOR_PATH"
# fail for missing yarn in .yarn/releases
fail_missing_yarn_vendor "$BUILD_DIR" "$VENDOR_PATH"
fi
fi

### Configure package manager cache directories
[ ! "$YARN_CACHE_FOLDER" ] && YARN_CACHE_FOLDER=$(mktemp -d -t yarncache.XXXXX)
[ ! "$NPM_CONFIG_CACHE" ] && NPM_CONFIG_CACHE=$(mktemp -d -t npmcache.XXXXX)
export YARN_CACHE_FOLDER NPM_CONFIG_CACHE
[ ! "$PNPM_CONFIG_CACHE" ] && PNPM_CONFIG_CACHE=$(mktemp -d -t pnpmcache.XXXXX)
export YARN_CACHE_FOLDER NPM_CONFIG_CACHE PNPM_CONFIG_CACHE

install_bins() {
local node_engine npm_engine yarn_engine npm_version node_version jvm_engine jvm_version basex_engine basex_version
local node_engine npm_engine yarn_engine node_version package_manager pnpm_engine jvm_engine jvm_version basex_engine basex_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")
pnpm_engine=$(read_json "$BUILD_DIR/package.json" ".engines.pnpm")
package_manager=$(read_json "$BUILD_DIR/package.json" ".packageManager")
jvm_engine=$(read_json "$BUILD_DIR/package.json" ".engines.jvm")
basex_engine=$(read_json "$BUILD_DIR/package.json" ".engines.basex")
saxon_engine=$(read_json "$BUILD_DIR/package.json" ".engines.saxon")
Expand All @@ -216,15 +225,27 @@ install_bins() {
meta_set "node-version-request" "$node_engine"
meta_set "npm-version-request" "$npm_engine"
meta_set "yarn-version-request" "$yarn_engine"
meta_set "jvm-version-request" "$jvm_engine"
meta_set "basex-version-request" "$basex_engine"
meta_set "saxon-version-request" "$saxon_engine"
meta_set "pnpm-version-request" "$pnpm_engine"
meta_set "package-manager-request" "$package_manager"

echo "engines.node (package.json): ${node_engine:-unspecified}"
echo "engines.npm (package.json): ${npm_engine:-unspecified (use default)}"

echo "engines.node (package.json): ${node_engine:-unspecified}"
echo "engines.npm (package.json): ${npm_engine:-unspecified (use default)}"
if $YARN || [ -n "$yarn_engine" ]; then
echo "engines.yarn (package.json): ${yarn_engine:-unspecified (use default)}"
echo "engines.yarn (package.json): ${yarn_engine:-unspecified (use default)}"
fi

if $PNPM || [ -n "$pnpm_engine" ]; then
echo "engines.pnpm (package.json): ${pnpm_engine:-unspecified (use default)}"
fi

if [ -n "$package_manager" ]; then
echo "packageManager (package.json): $(echo "$package_manager" | cut -d "+" -f 1)"
fi

meta_set "jvm-version-request" "$jvm_engine"
meta_set "basex-version-request" "$basex_engine"
meta_set "saxon-version-request" "$saxon_engine"
echo "engines.jvm (package.json): ${jvm_engine:-unspecified (use default)}"
echo "engines.basex (package.json): ${basex_engine:-unspecified (use default)}"
if [ -n "$saxon_engine" ]; then
Expand All @@ -234,6 +255,18 @@ install_bins() {

warn_node_engine "$node_engine"

if [ -n "$pnpm_engine" ] && [[ "$package_manager" == pnpm* ]]; then
warn_multiple_pnpm_version "$package_manager" "$pnpm_engine"
fi

if [ -n "$yarn_engine" ] && [[ "$package_manager" == yarn* ]]; then
warn_multiple_yarn_version "$package_manager" "$yarn_engine"
fi

if has_release_script "$BUILD_DIR" && [[ "$package_manager" == yarn* ]]; then
warn_yarn_release_script_with_package_manager "$package_manager" "$(get_yarn_path "$BUILD_DIR")"
fi

meta_set "build-step" "install-nodejs"
monitor "install-node-binary" install_nodejs "$node_engine" "$BUILD_DIR/.heroku/node"

Expand All @@ -255,17 +288,46 @@ install_bins() {
mcount "version.node.$node_version"
meta_set "node-version" "$node_version"

# Download yarn if there is a yarn.lock file or if the user
# has specified a version of yarn under "engines". We'll still
# only install using yarn if there is a yarn.lock file
if $YARN || [ -n "$yarn_engine" ]; then
meta_set "build-step" "install-yarn"
monitor "install-yarn-binary" install_yarn "$BUILD_DIR/.heroku/yarn" "$yarn_engine"
if ! has_release_script "$BUILD_DIR" && [[ "$package_manager" == yarn* ]]; then
meta_set "build-step" "install-yarn-using-corepack"
monitor "install-yarn-using-corepack" install_yarn_using_corepack_package_manager "$package_manager" "$node_version"
else
# Download yarn if there is a yarn.lock file or if the user
# has specified a version of yarn under "engines". We'll still
# only install using yarn if there is a yarn.lock file
if $YARN || [ -n "$yarn_engine" ]; then
meta_set "build-step" "install-yarn"
monitor "install-yarn-binary" install_yarn "$BUILD_DIR/.heroku/yarn" "$yarn_engine"
fi
fi

if $PNPM; then
meta_set "build-step" "install-pnpm-using-corepack"

default_pnpm_version="pnpm@latest"
using_default_pnpm=false

if [[ "$package_manager" == pnpm* ]]; then
package_manager="$package_manager"
elif [ -n "$pnpm_engine" ]; then
package_manager="pnpm@${pnpm_engine}"
else
using_default_pnpm=true
package_manager="$default_pnpm_version"
fi

monitor "install-pnpm-using-corepack" install_pnpm_using_corepack_package_manager "$package_manager" "$node_version" "$PNPM_CONFIG_CACHE"
if [ "$using_default_pnpm" == true ]; then
warn_default_pnpm_version_used "$default_pnpm_version"
fi
fi

if $YARN; then
mcount "version.yarn.$(yarn --version)"
meta_set "yarn-version" "$(yarn --version)"
elif $PNPM; then
mcount "version.pnpm.$(pnpm --version)"
meta_set "pnpm-version" "$(pnpm --version)"
else
mcount "version.npm.$(npm --version)"
meta_set "npm-version" "$(npm --version)"
Expand Down Expand Up @@ -396,7 +458,7 @@ restore_cache() {
elif [[ "$cache_status" == "valid" ]]; then
header "Restoring cache"
if [[ "$cache_directories" == "" ]]; then
restore_default_cache_directories "$BUILD_DIR" "$CACHE_DIR" "$YARN_CACHE_FOLDER" "$NPM_CONFIG_CACHE"
restore_default_cache_directories "$BUILD_DIR" "$CACHE_DIR" "$YARN_CACHE_FOLDER" "$NPM_CONFIG_CACHE" "$PNPM_CONFIG_CACHE"
else
restore_custom_cache_directories "$BUILD_DIR" "$CACHE_DIR" "$cache_directories"
fi
Expand Down Expand Up @@ -435,6 +497,8 @@ build_dependencies() {
yarn_2_install "$BUILD_DIR"
elif $YARN; then
yarn_node_modules "$BUILD_DIR"
elif $PNPM; then
pnpm_install "$BUILD_DIR" "$CACHE_DIR"
elif $PREBUILD; then
echo "Prebuild detected (node_modules already exists)"
npm_rebuild "$BUILD_DIR"
Expand Down Expand Up @@ -467,7 +531,7 @@ cache_build() {
:
elif [[ "$cache_directories" == "" ]]; then
header "Caching build"
save_default_cache_directories "$BUILD_DIR" "$CACHE_DIR" "$YARN_CACHE_FOLDER" "$NPM_CONFIG_CACHE"
save_default_cache_directories "$BUILD_DIR" "$CACHE_DIR" "$YARN_CACHE_FOLDER" "$NPM_CONFIG_CACHE" "$PNPM_CONFIG_CACHE"
else
header "Caching build"
save_custom_cache_directories "$BUILD_DIR" "$CACHE_DIR" "$cache_directories"
Expand All @@ -479,6 +543,8 @@ cache_build() {
prune_devdependencies() {
if $YARN || $YARN_2; then
yarn_prune_devdependencies "$BUILD_DIR" "$YARN_CACHE_FOLDER" "$BP_DIR"
elif $PNPM; then
pnpm_prune_devdependencies "$BUILD_DIR"
else
npm_prune_devdependencies "$BUILD_DIR"
fi
Expand Down

0 comments on commit 641604a

Please sign in to comment.