Merge pull request #135 from cerc-io/dboreham/fix-npm-builds

Fix various npm build issues

Former-commit-id: d94ed55642
This commit is contained in:
David Boreham 2023-01-19 11:34:19 -07:00 committed by GitHub
commit 0372504f44
4 changed files with 17 additions and 2 deletions

View File

@ -13,6 +13,8 @@ if [[ -z "${CERC_NPM_AUTH_TOKEN}" ]]; then
echo "CERC_NPM_AUTH_TOKEN is not set" >&2 echo "CERC_NPM_AUTH_TOKEN is not set" >&2
exit 1 exit 1
fi fi
# Exit on error
set -e
local_npm_registry_url=$1 local_npm_registry_url=$1
package_publish_version=$2 package_publish_version=$2
# TODO: make this a paramater and allow a list of scopes # TODO: make this a paramater and allow a list of scopes

View File

@ -17,6 +17,8 @@ if [[ $# -eq 2 ]]; then
else else
package_publish_version=$( cat package.json | jq -r .version ) package_publish_version=$( cat package.json | jq -r .version )
fi fi
# Exit on error
set -e
# Get the name of this package from package.json since we weren't passed that # Get the name of this package from package.json since we weren't passed that
package_name=$( cat package.json | jq -r .name ) package_name=$( cat package.json | jq -r .name )
local_npm_registry_url=$1 local_npm_registry_url=$1

View File

@ -14,14 +14,23 @@ if [[ $# -ne 2 ]]; then
echo "Illegal number of parameters" >&2 echo "Illegal number of parameters" >&2
exit 1 exit 1
fi fi
# Exit on error
set -e
target_package=$1 target_package=$1
local_npm_registry_url=$2 local_npm_registry_url=$2
# TODO: use jq rather than sed here: # TODO: use jq rather than sed here:
versioned_target_package=$(grep ${target_package} package.json | sed -e 's#[[:space:]]\{1,\}\"\('${target_package}'\)\":[[:space:]]\{1,\}\"\(.*\)\",#\1@\2#' ) 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 # Use yarn info to get URL checksums etc from the new registry
yarn_info_output=$(yarn info --json $versioned_target_package 2>/dev/null) yarn_info_output=$(yarn info --json $versioned_target_package 2>/dev/null)
# Code below parses out the values we need # First check if the target version actually exists.
# If it doesn't exist there will be no .data.dist.tarball element,
# and jq will output the string "null"
package_tarball=$(echo $yarn_info_output | jq -r .data.dist.tarball) package_tarball=$(echo $yarn_info_output | jq -r .data.dist.tarball)
if [[ $package_tarball == "null" ]]; then
echo "FATAL: Target package version ($versioned_target_package) not found" >&2
exit 1
fi
# Code below parses out the values we need
# When running inside a container, the registry can return a URL with the wrong host name due to proxying # When running inside a container, the registry can return a URL with the wrong host name due to proxying
# so we need to check if that has happened and fix the URL if so. # so we need to check if that has happened and fix the URL if so.
if ! [[ "${package_tarball}" =~ ^${local_npm_registry_url}.* ]]; then if ! [[ "${package_tarball}" =~ ^${local_npm_registry_url}.* ]]; then
@ -33,6 +42,7 @@ package_integrity=$(echo $yarn_info_output | jq -r .data.dist.integrity)
package_shasum=$(echo $yarn_info_output | jq -r .data.dist.shasum) package_shasum=$(echo $yarn_info_output | jq -r .data.dist.shasum)
package_resolved=${package_tarball}#${package_shasum} package_resolved=${package_tarball}#${package_shasum}
# Some strings need to be escaped so they work when passed to sed later # Some strings need to be escaped so they work when passed to sed later
escaped_package_integrity=$(printf '%s\n' "$package_integrity" | sed -e 's/[\/&]/\\&/g')
escaped_package_resolved=$(printf '%s\n' "$package_resolved" | sed -e 's/[\/&]/\\&/g') escaped_package_resolved=$(printf '%s\n' "$package_resolved" | sed -e 's/[\/&]/\\&/g')
escaped_target_package=$(printf '%s\n' "$target_package" | sed -e 's/[\/&]/\\&/g') escaped_target_package=$(printf '%s\n' "$target_package" | sed -e 's/[\/&]/\\&/g')
if [ -n "$CERC_SCRIPT_VERBOSE" ]; then if [ -n "$CERC_SCRIPT_VERBOSE" ]; then
@ -44,4 +54,4 @@ fi
# Use magic sed regex to replace the values in yarn.lock # Use magic sed regex to replace the values in yarn.lock
# Note: yarn.lock is not json so we can not use jq for this # Note: yarn.lock is not json so we can not use jq for this
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,\}resolved \).*$/\1'\"${escaped_package_resolved}\"'/' yarn.lock
sed -i -e '/^\"'${escaped_target_package}'.*\":$/ , /^\".*$/ s/^\([[:space:]]\{1,\}integrity \).*$/\1'${package_integrity}'/' yarn.lock sed -i -e '/^\"'${escaped_target_package}'.*\":$/ , /^\".*$/ s/^\([[:space:]]\{1,\}integrity \).*$/\1'${escaped_package_integrity}'/' yarn.lock

View File

@ -1,5 +1,6 @@
version: "1.0" version: "1.0"
name: fixturenet-laconicd name: fixturenet-laconicd
description: "A laconicd fixturenet"
repos: repos:
- cerc-io/laconicd - cerc-io/laconicd
- cerc-io/laconic-sdk - cerc-io/laconic-sdk