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

Update scripts to unlink deps in package.json for nested workspaces after builds & tests to reduce local changes #665

Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions scripts/build_packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,8 @@ for package in ${PACKAGES[@]} ; do
readonly BAZEL_BIN=$(bazel info bazel-bin)
echo_and_run cp -R "${BAZEL_BIN}/npm_package" ${DEST_DIR}
chmod -R u+w ${DEST_DIR}

# Unlink deps to undo local changes
${RULES_NODEJS_DIR}/scripts/unlink_deps.sh
)
done
4 changes: 4 additions & 0 deletions scripts/link_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set -eu -o pipefail
# -o pipefail: causes a pipeline to produce a failure return code if any command errors

readonly RULES_NODEJS_DIR=$(cd $(dirname "$0")/..; pwd)
readonly RELATIVE_DIR=$(pwd | cut -c 2- | cut -c ${#RULES_NODEJS_DIR}-)

echo_and_run() { echo "+ $@" ; "$@" ; }

Expand All @@ -20,6 +21,7 @@ sedi () {
sed "${sedi[@]}" "$@"
}

# Unlink first incase they are already linked
${RULES_NODEJS_DIR}/scripts/unlink_deps.sh

DEPS=()
Expand All @@ -44,6 +46,8 @@ if [[ ${DEPS:-} ]] ; then
${RULES_NODEJS_DIR}/scripts/check_deps.sh ${DEPS[@]}
fi

echo "Linking deps in ${RELATIVE_DIR}"

for package in ${PACKAGES[@]:-} ; do
# Find name of dist dir (the postfix $RANDOM changes each time it is re-generated)
results=$(ls -d ${RULES_NODEJS_DIR}/dist/npm_bazel_${package}\$* 2> /dev/null || :)
Expand Down
1 change: 1 addition & 0 deletions scripts/publish_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ for pkg in ${PACKAGES[@]} ; do (
cd packages/$pkg
${RULES_NODEJS_DIR}/scripts/link_deps.sh
echo_and_run ../../node_modules/.bin/bazel --output_base=$TMP run --workspace_status_command=../../scripts/current_version.sh //:npm_package.${NPM_COMMAND}
${RULES_NODEJS_DIR}/scripts/unlink_deps.sh
) done
1 change: 1 addition & 0 deletions scripts/test_e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ for e2eTest in ${E2E_TESTS[@]} ; do
printf "\n\nRunning e2e test ${e2eTest}\n"
${RULES_NODEJS_DIR}/scripts/link_deps.sh
echo_and_run yarn test
${RULES_NODEJS_DIR}/scripts/unlink_deps.sh
)
done
3 changes: 2 additions & 1 deletion scripts/test_examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ for example in ${EXAMPLES[@]} ; do
(
# Test example
if [[ ${example} == "vendored_node" && ${KERNEL_NAME} != Linux* ]] ; then
echo "Skipping vendored_node test as it only runs on Linux while we are executing on ${KERNEL_NAME}"
printf "\n\nSkipping vendored_node test as it only runs on Linux while we are executing on ${KERNEL_NAME}\n"
else
cd "${EXAMPLES_DIR}/${example}"
printf "\n\nRunning example ${example}\n"
Expand All @@ -26,6 +26,7 @@ for example in ${EXAMPLES[@]} ; do
if grep -q "\"e2e\":" package.json; then
echo_and_run yarn e2e
fi
${RULES_NODEJS_DIR}/scripts/unlink_deps.sh
fi
)
done
1 change: 1 addition & 0 deletions scripts/test_legacy_e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ for e2eTest in ${E2E_TESTS[@]} ; do
printf "\n\nRunning legacy e2e test ${e2eTest}\n"
${RULES_NODEJS_DIR}/scripts/link_deps.sh
echo_and_run yarn test
${RULES_NODEJS_DIR}/scripts/unlink_deps.sh
)
done
1 change: 1 addition & 0 deletions scripts/test_packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ for package in ${PACKAGES[@]} ; do
printf "\n\nTesting package ${package}\n"
${RULES_NODEJS_DIR}/scripts/link_deps.sh
echo_and_run yarn test
${RULES_NODEJS_DIR}/scripts/unlink_deps.sh
)
done
24 changes: 24 additions & 0 deletions scripts/unlink_all_deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

set -eu -o pipefail
# -e: exits if a command fails
# -u: errors if an variable is referenced before being set
# -o pipefail: causes a pipeline to produce a failure return code if any command errors

readonly RULES_NODEJS_DIR=$(cd $(dirname "$0")/..; pwd)
cd ${RULES_NODEJS_DIR}

for rootDir in packages examples e2e internal/e2e ; do
(
cd ${rootDir}
for subDir in $(ls) ; do
[[ -d "${subDir}" ]] || continue
(
cd ${subDir}
if [[ -e 'package.json' ]] ; then
${RULES_NODEJS_DIR}/scripts/unlink_deps.sh
fi
)
done
)
done
3 changes: 3 additions & 0 deletions scripts/unlink_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set -eu -o pipefail
# -o pipefail: causes a pipeline to produce a failure return code if any command errors

readonly RULES_NODEJS_DIR=$(cd $(dirname "$0")/..; pwd)
readonly RELATIVE_DIR=$(pwd | cut -c 2- | cut -c ${#RULES_NODEJS_DIR}-)

echo_and_run() { echo "+ $@" ; "$@" ; }

Expand All @@ -20,6 +21,8 @@ sedi () {
sed "${sedi[@]}" "$@"
}

echo "Unlinking deps in ${RELATIVE_DIR}"

# Replaces "file://..." with absolute path to generated npm package under /dist/npm_bazel_foobar$RANDOM
# back to "bazel://@npm_bazel_foobar//:npm_package"
echo_and_run sedi "s#\"file://${RULES_NODEJS_DIR}/dist/npm_bazel_\([a-z_]*\)\$*[0-9]*\"#\"bazel://@npm_bazel_\1//:npm_package\"#" package.json