From bf8be9bf3a2aea25afb3bdda5b845a461f37d4e1 Mon Sep 17 00:00:00 2001 From: Takashi Kokubun Date: Mon, 16 Mar 2026 16:06:39 -0700 Subject: [PATCH] Use explicit npm dist-tag to allow publishing older versions When publishing a backport release (e.g. 1.8.1) after a newer version (e.g. 1.9.0) already exists on npm, `npm publish` fails because it tries to move the `latest` tag to a lower version. Fix this by comparing the package version against the current `latest` on npm and using a `stable-X.Y` dist-tag for older releases. --- .github/workflows/publish-npm.yml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish-npm.yml b/.github/workflows/publish-npm.yml index e14746a155..5a27aecd4c 100644 --- a/.github/workflows/publish-npm.yml +++ b/.github/workflows/publish-npm.yml @@ -42,5 +42,17 @@ jobs: - name: Update npm run: npm install -g npm@latest - - run: npm publish + - name: Determine npm tag + id: npm-tag + run: | + PACKAGE_VERSION=$(node -p "require('./javascript/package.json').version") + LATEST_VERSION=$(npm view @ruby/prism version 2>/dev/null || echo "0.0.0") + if npx semver "$PACKAGE_VERSION" -r ">$LATEST_VERSION"; then + echo "tag=latest" >> "$GITHUB_OUTPUT" + else + MINOR=$(echo "$PACKAGE_VERSION" | cut -d. -f1,2) + echo "tag=stable-$MINOR" >> "$GITHUB_OUTPUT" + fi + + - run: npm publish --tag ${{ steps.npm-tag.outputs.tag }} working-directory: javascript