@@ -245,16 +245,16 @@ fetch_package_metadata() {
245245 # npm can return either {"error":"..."} or a plain JSON string like "version not found: test"
246246 if echo " $PACKAGE_METADATA " | grep -q ' "error"' ; then
247247 local error_msg
248- error_msg=$( echo " $PACKAGE_METADATA " | grep -o ' "error": "[^"]*"' | cut -d' "' -f4)
249- error " Failed to fetch version '${version_path} ': ${error_msg:- unknown error} "
248+ error_msg=$( echo " $PACKAGE_METADATA " | grep -o ' "error" *: * "[^"]*"' | cut -d' "' -f4)
249+ error " Failed to fetch version '${version_path} ': ${error_msg:- unknown error} \n URL: $metadata_url "
250250 fi
251251 # Check if response is a plain error string (not a valid package object)
252252 # Use '"version":' to match JSON property, not just the word "version"
253- if ! echo " $PACKAGE_METADATA " | grep -q ' "version":' ; then
253+ if ! echo " $PACKAGE_METADATA " | grep -q ' "version" * :' ; then
254254 # Remove surrounding quotes from the error message if present
255255 local error_msg
256256 error_msg=$( echo " $PACKAGE_METADATA " | sed ' s/^"//;s/"$//' )
257- error " Failed to fetch version '${version_path} ': ${error_msg:- unknown error} "
257+ error " Failed to fetch version '${version_path} ': ${error_msg:- unknown error} \n URL: $metadata_url "
258258 fi
259259 fi
260260 # PACKAGE_METADATA is set as a global variable, no need to echo
@@ -266,7 +266,7 @@ get_version_from_metadata() {
266266 # Call fetch_package_metadata to populate PACKAGE_METADATA global
267267 # Don't use command substitution as it would swallow the exit from error()
268268 fetch_package_metadata
269- RESOLVED_VERSION=$( echo " $PACKAGE_METADATA " | grep -o ' "version": "[^"]*"' | head -1 | cut -d' "' -f4)
269+ RESOLVED_VERSION=$( echo " $PACKAGE_METADATA " | grep -o ' "version" *: * "[^"]*"' | head -1 | cut -d' "' -f4)
270270 if [ -z " $RESOLVED_VERSION " ]; then
271271 error " Failed to extract version from package metadata"
272272 fi
0 commit comments