File tree Expand file tree Collapse file tree 1 file changed +14
-6
lines changed Expand file tree Collapse file tree 1 file changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -80,14 +80,22 @@ get_version() {
8080 VERSION=" $1 "
8181 info " Installing specified version: $VERSION "
8282 else
83- info " No version specified. Fetching the latest version from crates.io..."
84- CRATES_API_URL=" https://crates.io/api/v1/crates/${CARGO_PKG_NAME} "
85- VERSION=" v$( curl -sL " $CRATES_API_URL " | grep -o ' "max_version":"[^"]*"' | head -1 | sed ' s/"max_version":"\([^"]*\)"/\1/' ) "
83+ info " No version specified. Fetching the latest version from crates.io index..."
8684
87- if [ -z " $VERSION " ]; then
88- error " Could not determine the latest version from crates.io. Please check the crate name."
85+ # Uses index.crates.io which is more reliable than the rate-limited Crates API
86+ # Path structure: /first_two_chars/next_two_chars/full_name
87+ CRATE_FIRST_TWO=$( echo " ${CARGO_PKG_NAME} " | cut -c1-2)
88+ CRATE_NEXT_TWO=$( echo " ${CARGO_PKG_NAME} " | cut -c3-4)
89+
90+ INDEX_URL=" https://index.crates.io/${CRATE_FIRST_TWO} /${CRATE_NEXT_TWO} /${CARGO_PKG_NAME} "
91+
92+ # The index returns newline-delimited JSON; extract the version from the last line
93+ VERSION=" v$( curl -sL " $INDEX_URL " | tail -1 | grep -o ' "vers":"[^"]*"' | sed ' s/"vers":"\([^"]*\)"/\1/' ) "
94+
95+ if [ -z " $VERSION " ] || [ " $VERSION " = " v" ]; then
96+ error " Could not determine the latest version from crates.io index. Please check the crate name or specify a version manually."
8997 fi
90- info " Latest version found on crates.io : $VERSION "
98+ info " Latest version found: $VERSION "
9199 fi
92100}
93101
You can’t perform that action at this time.
0 commit comments