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

Cache node modules and meteor build #195

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
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
22 changes: 21 additions & 1 deletion bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,14 @@ echo "-----> and npm: `$METEOR_NPM --version`"
# If we use npm on root, run npm install. Don't use `--production` here, as we
# may need devDependencies (e.g. webpack) in order to build the meteor app.
if [ -e "$APP_SOURCE_DIR"/package.json ]; then
mkdir -p "$CACHE_DIR/meteor-dev-modules"
if [ -n "$(ls -A $CACHE_DIR/meteor-dev-modules)" ]; then
echo "-----> Reusing development node_modules cache"
mkdir -p "$APP_SOURCE_DIR/node_modules"
mv "$CACHE_DIR/meteor-dev-modules/*" "$APP_SOURCE_DIR/node_modules"
fi
$METEOR_NPM install
cp -a "$APP_SOURCE_DIR/node_modules/*" "$CACHE_DIR/meteor-dev-modules/"
fi

# Related to https://github.com/meteor/meteor/issues/2796 and
Expand All @@ -193,6 +200,12 @@ echo "-----> Building Meteor app with ROOT_URL: $ROOT_URL"
BUNDLE_DEST=`mktemp -d "$BUILDPACK_DIR/build-XXXX"`

# The actual invocation of `meteor build`!
mkdir -p "$CACHE_DIR/meteor-build"
rm -rf "$APP_SOURCE_DIR"/.meteor/local
if [ -n "$(ls -A $CACHE_DIR/meteor-build)" ]; then
echo "-----> Reusing meteor build cache"
fi
ln -s "$CACHE_DIR/meteor-build" "$APP_SOURCE_DIR/.meteor/local"
METEOR build $BUILD_OPTIONS --server $ROOT_URL $SERVER_ONLY_FLAG --directory $BUNDLE_DEST

echo "-----> Moving built slug to $COMPILE_DIR/app"
Expand All @@ -203,7 +216,14 @@ rmdir $BUNDLE_DEST
echo "-----> Installing npm production dependencies on built slug"
if [ -e "$COMPILE_DIR"/app/programs/server/package.json ]; then
cd "$COMPILE_DIR"/app/programs/server
mkdir -p "$CACHE_DIR/meteor-prod-modules"
if [ -n "$(ls -A $CACHE_DIR/meteor-prod-modules)" ]; then
echo "-----> Reusing production node_modules cache"
fi
mv "$CACHE_DIR/meteor-prod-modules/*" "$COMPILE_DIR/app/programs/server/node_modules" &> /dev/null || true
rm -rf "$CACHE_DIR/meteor-prod-modules"
$METEOR_NPM install --production
cp -R "$COMPILE_DIR/app/programs/server/node_modules" "$CACHE_DIR/meteor-prod-modules"
cd "$APP_SOURCE_DIR"
fi

Expand Down Expand Up @@ -235,5 +255,5 @@ done
#
if [ -n "${BUILDPACK_CLEAR_CACHE+1}" ]; then
echo "-----> Clearing cache dir."
rm -rf $METEOR_DIR
rm -rf "$CACHE_DIR/*"
fi