Skip to content

Commit bf8be9b

Browse files
committed
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.
1 parent eceb44d commit bf8be9b

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

.github/workflows/publish-npm.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,17 @@ jobs:
4242
- name: Update npm
4343
run: npm install -g npm@latest
4444

45-
- run: npm publish
45+
- name: Determine npm tag
46+
id: npm-tag
47+
run: |
48+
PACKAGE_VERSION=$(node -p "require('./javascript/package.json').version")
49+
LATEST_VERSION=$(npm view @ruby/prism version 2>/dev/null || echo "0.0.0")
50+
if npx semver "$PACKAGE_VERSION" -r ">$LATEST_VERSION"; then
51+
echo "tag=latest" >> "$GITHUB_OUTPUT"
52+
else
53+
MINOR=$(echo "$PACKAGE_VERSION" | cut -d. -f1,2)
54+
echo "tag=stable-$MINOR" >> "$GITHUB_OUTPUT"
55+
fi
56+
57+
- run: npm publish --tag ${{ steps.npm-tag.outputs.tag }}
4658
working-directory: javascript

0 commit comments

Comments
 (0)