cloudflare/cloudflare-typescript

Public

mirrored fromhttps://github.com/cloudflare/cloudflare-typescriptAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
main

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

bin/publish-npm

60lines · modecode

1#!/usr/bin/env bash
2
3set -eux
4
5yarn build
6cd dist
7
8# Get package name and version from package.json
9PACKAGE_NAME="$(jq -r -e '.name' ./package.json)"
10VERSION="$(jq -r -e '.version' ./package.json)"
11
12# Get latest version from npm
13#
14# If the package doesn't exist, npm will return:
15# {
16# "error": {
17# "code": "E404",
18# "summary": "Unpublished on 2025-06-05T09:54:53.528Z",
19# "detail": "'the_package' is not in this registry..."
20# }
21# }
22NPM_INFO="$(npm view "$PACKAGE_NAME" version --json 2>/dev/null || true)"
23
24# Check if we got an E404 error
25if echo "$NPM_INFO" | jq -e '.error.code == "E404"' > /dev/null 2>&1; then
26 # Package doesn't exist yet, no last version
27 LAST_VERSION=""
28elif echo "$NPM_INFO" | jq -e '.error' > /dev/null 2>&1; then
29 # Report other errors
30 echo "ERROR: npm returned unexpected data:"
31 echo "$NPM_INFO"
32 exit 1
33else
34 # Success - get the version
35 LAST_VERSION=$(echo "$NPM_INFO" | jq -r '.') # strip quotes
36fi
37
38# Check if current version is pre-release (e.g. alpha / beta / rc)
39CURRENT_IS_PRERELEASE=false
40if [[ "$VERSION" =~ -([a-zA-Z]+) ]]; then
41 CURRENT_IS_PRERELEASE=true
42 CURRENT_TAG="${BASH_REMATCH[1]}"
43fi
44
45# Check if last version is a stable release
46LAST_IS_STABLE_RELEASE=true
47if [[ -z "$LAST_VERSION" || "$LAST_VERSION" =~ -([a-zA-Z]+) ]]; then
48 LAST_IS_STABLE_RELEASE=false
49fi
50
51# Use a corresponding alpha/beta tag if there already is a stable release and we're publishing a prerelease.
52if $CURRENT_IS_PRERELEASE && $LAST_IS_STABLE_RELEASE; then
53 TAG="$CURRENT_TAG"
54else
55 TAG="latest"
56fi
57
58# Publish with the appropriate tag
59unset NODE_AUTH_TOKEN
60npm publish --provenance --tag "$TAG"
61