cloudflare/cloudflare-typescript

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v7

Branches

Tags

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

Clone

HTTPS

Download ZIP

bin/publish-npm

61lines · modecode

1#!/usr/bin/env bash
2
3set -eux
4
5npm config set '//registry.npmjs.org/:_authToken' "$NPM_TOKEN"
6
7yarn build
8cd dist
9
10# Get package name and version from package.json
11PACKAGE_NAME="$(jq -r -e '.name' ./package.json)"
12VERSION="$(jq -r -e '.version' ./package.json)"
13
14# Get latest version from npm
15#
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# }
24NPM_INFO="$(npm view "$PACKAGE_NAME" version --json 2>/dev/null || true)"
25
26# Check if we got an E404 error
27if 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=""
30elif 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
35else
36 # Success - get the version
37 LAST_VERSION=$(echo "$NPM_INFO" | jq -r '.') # strip quotes
38fi
39
40# Check if current version is pre-release (e.g. alpha / beta / rc)
41CURRENT_IS_PRERELEASE=false
42if [[ "$VERSION" =~ -([a-zA-Z]+) ]]; then
43 CURRENT_IS_PRERELEASE=true
44 CURRENT_TAG="${BASH_REMATCH[1]}"
45fi
46
47# Check if last version is a stable release
48LAST_IS_STABLE_RELEASE=true
49if [[ -z "$LAST_VERSION" || "$LAST_VERSION" =~ -([a-zA-Z]+) ]]; then
50 LAST_IS_STABLE_RELEASE=false
51fi
52
53# Use a corresponding alpha/beta tag if there already is a stable release and we're publishing a prerelease.
54if $CURRENT_IS_PRERELEASE && $LAST_IS_STABLE_RELEASE; then
55 TAG="$CURRENT_TAG"
56else
57 TAG="latest"
58fi
59
60# Publish with the appropriate tag
61yarn publish --tag "$TAG"
62