#!/bin/bash set -eux -o pipefail # This script is used in the "npm pack" step in our CI build pipelines. # It runs (p)npm pack for all packages and outputs them to a folder. # It also outputs a packagePublishOrder file per feed that contains the order in which the packages should be published. echo PACKAGE_MANAGER=$PACKAGE_MANAGER echo RELEASE_GROUP=$RELEASE_GROUP echo STAGING_PATH=$STAGING_PATH mkdir -p $STAGING_PATH/pack/tarballs/ mkdir $STAGING_PATH/test-files/ # Runs pack on all packages in the release group and moves the tarballs to the staging folder. # If test files are found, they are moved to the test-files folder. # Note: use of package's pack:tests is only supported for pnpm as PACKAGE_MANAGER. if [ -f ".releaseGroup" ]; then if [ "$PACKAGE_MANAGER" == "pnpm" ]; then flub exec --no-private --concurrency=1 --releaseGroup $RELEASE_GROUP -- "pnpm --if-present pack:tests" fi flub exec --no-private --concurrency=1 --releaseGroup $RELEASE_GROUP -- "$PACKAGE_MANAGER pack" flub exec --no-private --concurrency=1 --releaseGroup $RELEASE_GROUP -- "mv -t $STAGING_PATH/pack/tarballs/ ./*.tgz" flub exec --no-private --releaseGroup $RELEASE_GROUP -- "[ ! -f ./*test-files.tar ] || (echo 'test files found' && mv -t $STAGING_PATH/test-files/ ./*test-files.tar)" # Clean up generated files that are listed in a package's "files" array (e.g. oclif.manifest.json) after packing. # These are produced during build and intentionally shipped in the published tarball, but should not linger in # the working tree. This cleanup deliberately runs here rather than in a package "postpack" script: under # pnpm >=11, `pnpm pack` re-stats every "files" entry after postpack runs and fails with ENOENT if postpack # deleted one. Running it here, after all packs complete, avoids that while still cleaning the working tree. flub exec --no-private --releaseGroup $RELEASE_GROUP -- "pnpm run --if-present clean:manifest" else if [ "$PACKAGE_MANAGER" == "pnpm" ]; then pnpm --if-present pack:tests fi $PACKAGE_MANAGER pack mv -t $STAGING_PATH/pack/tarballs/ ./*.tgz fi SCRIPT_DIRECTORY="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" bash "$SCRIPT_DIRECTORY/generate-package-publish-order.sh"