From 717391d835fc7af8a9a18138c39e1a17e82b9210 Mon Sep 17 00:00:00 2001 From: David Boreham Date: Mon, 19 Dec 2022 09:37:24 -0700 Subject: [PATCH] Add comments --- .../cerc-builder-js/yarn-local-registry-fixup.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/container-build/cerc-builder-js/yarn-local-registry-fixup.sh b/container-build/cerc-builder-js/yarn-local-registry-fixup.sh index b16585cf..db04c433 100755 --- a/container-build/cerc-builder-js/yarn-local-registry-fixup.sh +++ b/container-build/cerc-builder-js/yarn-local-registry-fixup.sh @@ -1,6 +1,12 @@ #!/bin/bash # Usage: yarn-local-registry-fixup.sh # Assumes package.json and yarn.lock are in the cwd +# The purpose of this script is to take a project cloned from git +# and "fixup" its yarn.lock file such that specified dependency +# will be fetched from a repository other than the one used when +# yarn.lock was generated. It updates all checksums using data +# from the "new" registry (because due to embedded timestamps etc +# the same source code re-built later will not have the same checksum). if [ -n "$CERC_SCRIPT_DEBUG" ]; then set -x fi @@ -10,11 +16,14 @@ if [[ $# -ne 1 ]]; then fi target_package=$1 versioned_target_package=$(grep ${target_package} package.json | sed -e 's#[[:space:]]\{1,\}\"\('${target_package}'\)\":[[:space:]]\{1,\}\"\(.*\)\",#\1@\2#' ) +# Use yarn info to get URL checksums etc from the new registry yarn_info_output=$(yarn info --json $versioned_target_package 2>/dev/null) +# Code below parses out the values we need package_tarball=$(echo $yarn_info_output | jq -r .data.dist.tarball) package_integrity=$(echo $yarn_info_output | jq -r .data.dist.integrity) package_shasum=$(echo $yarn_info_output | jq -r .data.dist.shasum) package_resolved=${package_tarball}#${package_shasum} +# Some strings need to be escaped so they work when passed to sed later escaped_package_resolved=$(printf '%s\n' "$package_resolved" | sed -e 's/[\/&]/\\&/g') escaped_target_package=$(printf '%s\n' "$target_package" | sed -e 's/[\/&]/\\&/g') if [ -n "$CERC_SCRIPT_VERBOSE" ]; then @@ -23,5 +32,6 @@ if [ -n "$CERC_SCRIPT_VERBOSE" ]; then echo "Shasum: ${package_shasum}" echo "Resolved: ${package_resolved}" fi +# Use magic sed regex to replace the values in yarn.lock sed -i -e '/^\"'${escaped_target_package}'.*\":$/ , /^\".*$/ s/^\([[:space:]]\{1,\}resolved \).*$/\1'\"${escaped_package_resolved}\"'/' yarn.lock sed -i -e '/^\"'${escaped_target_package}'.*\":$/ , /^\".*$/ s/^\([[:space:]]\{1,\}integrity \).*$/\1'${package_integrity}'/' yarn.lock