@@ -47,7 +47,7 @@ while [[ $# -gt 0 ]]; do
4747 echo " "
4848 echo " Options:"
4949 echo " --yes, -y Skip confirmation prompt"
50- echo " --no-cleanup Don't restore files after publishing "
50+ echo " --no-cleanup Keep modified files after successful publish "
5151 echo " --help Show this help message"
5252 echo " "
5353 echo " Examples:"
8787SHA=$( git rev-parse --short HEAD)
8888SNAPSHOT=" $TAG -$SHA " # Pass tag with SHA to changeset (it will add timestamp)
8989
90- # ------------------------------------------------------------------
91- # Set up cleanup trap (unless disabled)
92- # ------------------------------------------------------------------
93- if [[ " $NO_CLEANUP " != " true " ]] ; then
94- trap ' echo -e "\n${YELLOW}Cleaning up...${NC}" && \
95- git restore --source=HEAD --worktree --staged \
96- "**/package.json" "**/jsr.json" "**/CHANGELOG.md" 2>/dev/null || true; \
97- git restore --source=HEAD --worktree --staged \
98- pnpm-lock.yaml 2>/dev/null || true; \
99- git restore --source=HEAD --worktree --staged \
100- .changeset/pre.json 2>/dev/null || true; \
101- git clean -fd .changeset 2>/dev/null || true ' EXIT
102- fi
90+ # Cleanup function (to be called after successful publish)
91+ cleanup_snapshot_files () {
92+ echo " "
93+ echo -e " ${YELLOW} Cleaning up snapshot files... ${NC} "
94+ git restore --source=HEAD --worktree --staged \
95+ " **/package.json " " **/jsr.json " " **/CHANGELOG.md " 2> /dev/null || true
96+ git restore --source=HEAD --worktree --staged \
97+ pnpm-lock.yaml 2> /dev/null || true
98+ git restore --source=HEAD --worktree --staged \
99+ .changeset/pre.json 2> /dev/null || true
100+ git clean -fd .changeset 2> /dev/null || true
101+ echo -e " ${GREEN} ✓ Cleanup complete ${NC} "
102+ }
103103
104104# ------------------------------------------------------------------
105105# Display snapshot version info
@@ -184,10 +184,12 @@ echo ""
184184echo -e " ${BOLD} Packages to publish:${NC} "
185185echo " "
186186
187- # Collect npm packages
187+ # Collect npm packages (only those matching current snapshot tag)
188188NPM_PKGS=()
189189while IFS= read -r -d ' ' file; do
190- PKG_INFO=$( jq -r ' select(.version | test("^0\\.0\\.0-")) | .name + "@" + .version' " $file " 2> /dev/null)
190+ PKG_INFO=$( jq -r --arg snapshot " $SNAPSHOT " \
191+ ' select(.version | test("^0\\.0\\.0-" + $snapshot)) | .name + "@" + .version' \
192+ " $file " 2> /dev/null)
191193 if [[ -n " $PKG_INFO " ]]; then
192194 NPM_PKGS+=(" $PKG_INFO " )
193195 NAME=$( echo " $PKG_INFO " | cut -d' @' -f1-2)
@@ -200,7 +202,7 @@ done < <(find pkgs -name package.json -not -path "*/node_modules/*" -print0)
200202# Check for JSR package (edge-worker)
201203if [[ -f pkgs/edge-worker/jsr.json ]]; then
202204 JSR_VERSION=$( jq -r ' .version' pkgs/edge-worker/jsr.json)
203- if [[ " $JSR_VERSION " =~ ^0\. 0\. 0- ]]; then
205+ if [[ " $JSR_VERSION " =~ ^0\. 0\. 0-${SNAPSHOT} ]]; then
204206 echo -e " ${GREEN} ✓${NC} ${BOLD} @pgflow/edge-worker${NC} (JSR)"
205207 echo -e " ${JSR_VERSION} "
206208 fi
@@ -262,14 +264,19 @@ echo -e "${YELLOW}━━━━━━━━━━━━━━━━━━━━
262264echo -e " ${BOLD} Publishing packages...${NC} "
263265echo " "
264266
267+ # Track publish success
268+ NPM_SUCCESS=false
269+ JSR_SUCCESS=true # Default true (only set false if JSR package exists and fails)
270+
265271# Publish to npm
266272echo -e " ${BOLD} Publishing to npm...${NC} "
267273NPM_OUTPUT=$( pnpm exec changeset publish --tag snapshot 2>&1 )
268274echo " $NPM_OUTPUT "
269275if echo " $NPM_OUTPUT " | grep -qi " published" ; then
270276 echo -e " ${GREEN} ✓ npm packages published${NC} "
277+ NPM_SUCCESS=true
271278else
272- echo -e " ${RED} ✗ npm publish may have failed - check output above${NC} "
279+ echo -e " ${RED} ✗ npm publish failed - check output above${NC} "
273280fi
274281
275282# Publish to JSR
@@ -279,8 +286,25 @@ if [[ -f pkgs/edge-worker/jsr.json ]]; then
279286 if ( cd pkgs/edge-worker && pnpm jsr publish --allow-slow-types --allow-dirty ) ; then
280287 echo -e " ${GREEN} ✓ JSR package published${NC} "
281288 else
282- echo -e " ${YELLOW} ⚠ JSR publish failed${NC} "
289+ echo -e " ${RED} ✗ JSR publish failed${NC} "
290+ JSR_SUCCESS=false
291+ fi
292+ fi
293+
294+ # ------------------------------------------------------------------
295+ # Cleanup snapshot files (only if publish succeeded)
296+ # ------------------------------------------------------------------
297+ if [[ " $NPM_SUCCESS " == " true" ]] && [[ " $JSR_SUCCESS " == " true" ]]; then
298+ if [[ " $NO_CLEANUP " != " true" ]]; then
299+ cleanup_snapshot_files
283300 fi
301+ else
302+ echo " "
303+ echo -e " ${RED} ✗ Publishing failed - keeping files for debugging${NC} "
304+ echo -e " ${YELLOW} Run the following to clean up manually:${NC} "
305+ echo -e " ${BLUE} git restore --source=HEAD --worktree --staged \" **/package.json\" \" **/jsr.json\" \" **/CHANGELOG.md\" pnpm-lock.yaml .changeset/pre.json${NC} "
306+ echo -e " ${BLUE} git clean -fd .changeset${NC} "
307+ exit 1
284308fi
285309
286310# ------------------------------------------------------------------
0 commit comments