git: f97eed6954b4 - main - Tools/scripts: Add npmjs-get-latest-version.sh
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 01 Oct 2025 08:44:37 UTC
The branch main has been updated by yuri:
URL: https://cgit.FreeBSD.org/ports/commit/?id=f97eed6954b4799a449d1cbcf9a0149b253c8d75
commit f97eed6954b4799a449d1cbcf9a0149b253c8d75
Author: Yuri Victorovich <yuri@FreeBSD.org>
AuthorDate: 2025-10-01 03:47:49 +0000
Commit: Yuri Victorovich <yuri@FreeBSD.org>
CommitDate: 2025-10-01 08:44:28 +0000
Tools/scripts: Add npmjs-get-latest-version.sh
---
Tools/scripts/npmjs-get-latest-version.sh | 45 +++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/Tools/scripts/npmjs-get-latest-version.sh b/Tools/scripts/npmjs-get-latest-version.sh
new file mode 100755
index 000000000000..122211f03df8
--- /dev/null
+++ b/Tools/scripts/npmjs-get-latest-version.sh
@@ -0,0 +1,45 @@
+#!/bin/sh
+#
+# MAINTAINER: yuri@FreeBSD.org
+
+set -e
+set -o pipefail
+
+export LC_ALL=C
+
+##
+## npmjs-get-latest-version.sh: retrieves the latest version of a given Node.js package as registered on https://registry.npmjs.org
+##
+
+# args
+
+PACKAGE_NAME="$1"
+
+if [ -z "$PACKAGE_NAME" ]; then
+ echo "Usage: $0 <package-name>"
+ echo "Example: $0 @github/copilot"
+ echo "Example: $0 express"
+ exit 1
+fi
+
+# check that packaged dependencies are installed
+
+for dep in curl jq; do
+ if ! which $dep >/dev/null 2>&1; then
+ echo "error: the '$dep' dependency is missing"
+ if [ $dep = "curl" ]; then
+ echo "... please install the 'curl' package"
+ elif [ $dep = "jq" ]; then
+ echo "... please install the 'jq' package"
+ fi
+ exit 1
+ fi
+done
+
+
+# MAIN
+
+curl -H "Accept: application/json" https://registry.npmjs.org/$PACKAGE_NAME/latest 2>/dev/null |
+ grep -v "Not Found" |
+ jq -r '.version' ||
+ ! echo "failed to find the Node.js package '$PACKAGE_NAME'"