Skip to content

Commit

Permalink
chore: Generate single package-lock.json artifact
Browse files Browse the repository at this point in the history
Signed-off-by: Anatolii Bazko <[email protected]>
  • Loading branch information
tolusha committed Mar 4, 2025
1 parent 511a225 commit f803f68
Show file tree
Hide file tree
Showing 3 changed files with 28,730 additions and 5 deletions.
37 changes: 32 additions & 5 deletions build/artifacts/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ set -e
SCRIPT_DIR=$(dirname "$0")
ROOT_DIR=$(realpath "$SCRIPT_DIR/../..")
ARTIFACTS_LOCK_YAML="$SCRIPT_DIR/artifacts.lock.yaml"
ALL_PACKAGES_LOCK_JSON="$SCRIPT_DIR/package-lock.json"
ALL_PACKAGES_JSON="$SCRIPT_DIR/package.json"

run () {
makeArtifactsLockYaml () {
rm -f $ARTIFACTS_LOCK_YAML

echo "---" >> "$ARTIFACTS_LOCK_YAML"
Expand All @@ -35,7 +37,7 @@ run () {
if [[ ! $SHA256 == "null" ]]; then
FILENAME="$PLUGIN.$VERSION.vsix"
DOWNLOAD_URL="$REPOSITORY/releases/download/v$VERSION/$FILENAME"
check_existance "$DOWNLOAD_URL"
checkUrlExistence "$DOWNLOAD_URL"

echo " # $PLUGIN" >> "$ARTIFACTS_LOCK_YAML"
echo " - download_url: $DOWNLOAD_URL" >> "$ARTIFACTS_LOCK_YAML"
Expand Down Expand Up @@ -66,7 +68,7 @@ run () {
esac

DOWNLOAD_URL="https://github.com/microsoft/ripgrep-prebuilt/releases/download/${RG_VERSION}/ripgrep-${RG_VERSION}-${RG_ARCH_SUFFIX}.tar.gz"
check_existance "$DOWNLOAD_URL"
checkUrlExistence "$DOWNLOAD_URL"

read -r SHA256 rest <<< "$(curl -sL "$DOWNLOAD_URL" | shasum -a 256)"

Expand All @@ -76,10 +78,30 @@ run () {
echo " checksum: sha256:$SHA256" >> "$ARTIFACTS_LOCK_YAML"
done

echo "[INFO] Done"
echo "[INFO] Completed ${ARTIFACTS_LOCK_YAML}"
}

check_existance() {
# Combine all package-lock.json files into a single file
# based on the package.json in the root directory
makeAllPackageLockJson () {
pushd "$ROOT_DIR" > /dev/null

jq '. | del(.packages."")' package-lock.json > "${ALL_PACKAGES_LOCK_JSON}"
find . -type f -name "package-lock.json" -print0 | while IFS= read -r -d $'\0' file; do
echo "[INFO] Processing file: $file"

jq '.packages | del(."") | . |= with_entries(.value.origin = .value.resolved)' "$file" > /tmp/package.json
OUTPUT=$(jq '.packages += input' "${ALL_PACKAGES_LOCK_JSON}" /tmp/package.json) && echo -n "${OUTPUT}" > "${ALL_PACKAGES_LOCK_JSON}"
done
echo "[INFO] Completed ${ALL_PACKAGES_LOCK_JSON}"

jq '. | del(.scripts)' package.json > "${ALL_PACKAGES_JSON}"
echo "[INFO] Completed ${ALL_PACKAGES_JSON}"

popd > /dev/null
}

checkUrlExistence() {
if curl -sfILo/dev/null "$1"; then
echo "[INFO] Valid url: $1"
else
Expand All @@ -88,4 +110,9 @@ check_existance() {
fi
}

run() {
makeArtifactsLockYaml
makeAllPackageLockJson
}

run
Loading

0 comments on commit f803f68

Please sign in to comment.