@@ -7,15 +7,35 @@ npm config set '//registry.npmjs.org/:_authToken' "$NPM_TOKEN"
7
7
yarn build
8
8
cd dist
9
9
10
+ # Get package name and version from package.json
11
+ PACKAGE_NAME=" $( jq -r -e ' .name' ./package.json) "
12
+ VERSION=" $( jq -r -e ' .version' ./package.json) "
13
+
10
14
# Get latest version from npm
11
15
#
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
18
- VERSION=" $( node -p " require('./package.json').version" ) "
16
+ # If the package doesn't exist, npm will return:
17
+ # {
18
+ # "error": {
19
+ # "code": "E404",
20
+ # "summary": "Unpublished on 2025-06-05T09:54:53.528Z",
21
+ # "detail": "'the_package' is not in this registry..."
22
+ # }
23
+ # }
24
+ NPM_INFO=" $( npm view " $PACKAGE_NAME " version --json 2> /dev/null || true) "
25
+
26
+ # Check if we got an E404 error
27
+ if echo " $NPM_INFO " | jq -e ' .error.code == "E404"' > /dev/null 2>&1 ; then
28
+ # Package doesn't exist yet, no last version
29
+ LAST_VERSION=" "
30
+ elif echo " $NPM_INFO " | jq -e ' .error' > /dev/null 2>&1 ; then
31
+ # Report other errors
32
+ echo " ERROR: npm returned unexpected data:"
33
+ echo " $NPM_INFO "
34
+ exit 1
35
+ else
36
+ # Success - get the version
37
+ LAST_VERSION=$( echo " $NPM_INFO " | jq -r ' .' ) # strip quotes
38
+ fi
19
39
20
40
# Check if current version is pre-release (e.g. alpha / beta / rc)
21
41
CURRENT_IS_PRERELEASE=false
0 commit comments