From 680f227967d5d32323d6bafe72ab8bb0be054c57 Mon Sep 17 00:00:00 2001 From: David Boreham Date: Wed, 14 Dec 2022 09:23:12 -0700 Subject: [PATCH] Add yarn fixup script for local registry --- container-build/cerc-builder-js/README.md | 11 +++++++- .../cerc-builder-js/build-npm-package.sh | 2 +- .../yarn-local-registry-fixup.sh | 27 +++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100755 container-build/cerc-builder-js/yarn-local-registry-fixup.sh diff --git a/container-build/cerc-builder-js/README.md b/container-build/cerc-builder-js/README.md index ea09f21e..c1a93e32 100644 --- a/container-build/cerc-builder-js/README.md +++ b/container-build/cerc-builder-js/README.md @@ -12,5 +12,14 @@ it is possible to build packages manually by invoking `docker run` , for example $ docker run -it --add-host host.docker.internal:host-gateway \ -v ${HOME}/cerc/laconic-sdk:/workspace cerc/builder-js \ sh -c 'cd /workspace && NPM_AUTH_TOKEN=6613572a28ebebaee20ccd90064251fa8c2b94f6 \ - /build-npm-package.sh http://host.docker.internal:3000/api/packages/cerc-io/npm/ 1.2.3-test' + /build-npm-package.sh http://host.docker.internal:3000/api/packages/cerc-io/npm/ 0.1.4' +``` + +or: + +``` +$ docker run --rm -it --add-host host.docker.internal:host-gateway \ + -v ${HOME}/cerc/laconic-registry-cli:/workspace cerc/builder-js \ + sh -c 'cd /workspace && NPM_AUTH_TOKEN=6613572a28ebebaee20ccd90064251fa8c2b94f6 \ + /build-npm-package.sh http://host.docker.internal:3000/api/packages/cerc-io/npm/ 0.1.4' ``` diff --git a/container-build/cerc-builder-js/build-npm-package.sh b/container-build/cerc-builder-js/build-npm-package.sh index cc2eeb26..9e5094b2 100755 --- a/container-build/cerc-builder-js/build-npm-package.sh +++ b/container-build/cerc-builder-js/build-npm-package.sh @@ -1,7 +1,7 @@ #!/bin/bash # Usage: build-npm-package.sh # Note: supply the registry auth token in NPM_AUTH_TOKEN -if [ -n "$CERC_ENABLE_SCRIPT_DEBUG" ]; then +if [ -n "$CERC_SCRIPT_DEBUG" ]; then set -x fi if [[ $# -ne 2 ]]; then diff --git a/container-build/cerc-builder-js/yarn-local-registry-fixup.sh b/container-build/cerc-builder-js/yarn-local-registry-fixup.sh new file mode 100755 index 00000000..b16585cf --- /dev/null +++ b/container-build/cerc-builder-js/yarn-local-registry-fixup.sh @@ -0,0 +1,27 @@ +#!/bin/bash +# Usage: yarn-local-registry-fixup.sh +# Assumes package.json and yarn.lock are in the cwd +if [ -n "$CERC_SCRIPT_DEBUG" ]; then + set -x +fi +if [[ $# -ne 1 ]]; then + echo "Illegal number of parameters" >&2 + exit 1 +fi +target_package=$1 +versioned_target_package=$(grep ${target_package} package.json | sed -e 's#[[:space:]]\{1,\}\"\('${target_package}'\)\":[[:space:]]\{1,\}\"\(.*\)\",#\1@\2#' ) +yarn_info_output=$(yarn info --json $versioned_target_package 2>/dev/null) +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} +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 + echo "Tarball: ${package_tarball}" + echo "Integrity: ${package_integrity}" + echo "Shasum: ${package_shasum}" + echo "Resolved: ${package_resolved}" +fi +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