@@ -4,19 +4,35 @@ set -eux
44
55npm config set ' //registry.npmjs.org/:_authToken' " $NPM_TOKEN "
66
7- # Build the project
87yarn build
9-
10- # Navigate to the dist directory
118cd dist
129
13- # Get the version from package.json
10+ # Get latest version from npm
11+ #
12+ # If the package doesn't exist, yarn will return
13+ # {"type":"error","data":"Received invalid response from npm."}
14+ # where .data.version doesn't exist so LAST_VERSION will be an empty string.
15+ LAST_VERSION=" $( yarn info --json 2> /dev/null | jq -r ' .data.version' ) "
16+
17+ # Get current version from package.json
1418VERSION=" $( node -p " require('./package.json').version" ) "
1519
16- # Extract the pre-release tag if it exists
20+ # Check if current version is pre-release (e.g. alpha / beta / rc)
21+ CURRENT_IS_PRERELEASE=false
1722if [[ " $VERSION " =~ -([a-zA-Z]+) ]]; then
18- # Extract the part before any dot in the pre-release identifier
19- TAG=" ${BASH_REMATCH[1]} "
23+ CURRENT_IS_PRERELEASE=true
24+ CURRENT_TAG=" ${BASH_REMATCH[1]} "
25+ fi
26+
27+ # Check if last version is a stable release
28+ LAST_IS_STABLE_RELEASE=true
29+ if [[ -z " $LAST_VERSION " || " $LAST_VERSION " =~ -([a-zA-Z]+) ]]; then
30+ LAST_IS_STABLE_RELEASE=false
31+ fi
32+
33+ # Use a corresponding alpha/beta tag if there already is a stable release and we're publishing a prerelease.
34+ if $CURRENT_IS_PRERELEASE && $LAST_IS_STABLE_RELEASE ; then
35+ TAG=" $CURRENT_TAG "
2036else
2137 TAG=" latest"
2238fi
0 commit comments