diff options
| author | Danilo M. <danix@danix.xyz> | 2026-07-09 10:22:44 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-07-09 10:22:44 +0200 |
| commit | e48715a01c6e63e50fda231ecc0c3b2d1213e421 (patch) | |
| tree | 4238853cfed87cfe1de44aa46d6ee4b10bd88be6 | |
| parent | 0d994f33425728d5fca1af54ddc69da545a596f9 (diff) | |
| download | mkhintfile-e48715a01c6e63e50fda231ecc0c3b2d1213e421.tar.gz mkhintfile-e48715a01c6e63e50fda231ecc0c3b2d1213e421.zip | |
feat: _registry_name_from_url helper for nvchecker autodetect
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
| -rwxr-xr-x | mkhint | 26 | ||||
| -rwxr-xr-x | tests/mkhint_test.sh | 24 |
2 files changed, 50 insertions, 0 deletions
@@ -817,6 +817,32 @@ _has_nvchecker_section() { "$NVCHECKER_CONFIG" } +# Extract a package name from a language-registry download URL. +# Args: <url> <prgnam-fallback>. Prints the parsed name, or the fallback +# (PRGNAM) when no host-specific pattern matches. +_registry_name_from_url() { + local url="$1" fallback="$2" + case "$url" in + *crates.io/api/v1/crates/*) + # .../crates/NAME/NAME-VER.crate or .../crates/NAME/VER/download + printf '%s' "${url#*crates.io/api/v1/crates/}" | cut -d/ -f1 + return 0 ;; + *rubygems.org/downloads/*) + # /downloads/NAME-VER.gem + local base="${url##*/downloads/}"; base="${base%.gem}" + printf '%s' "${base%-*}" + return 0 ;; + *registry.npmjs.org/*) + # /NAME/-/NAME-VER.tgz (NAME may be @scope/pkg) + printf '%s' "${url#*registry.npmjs.org/}" | sed 's|/-/.*||' + return 0 ;; + *hackage.haskell.org/package/*) + printf '%s' "${url#*hackage.haskell.org/package/}" | cut -d/ -f1 + return 0 ;; + esac + printf '%s' "$fallback" +} + # Append an nvchecker [pkg] section to NVCHECKER_CONFIG, auto-detecting the # source from the package's .info DOWNLOAD/HOMEPAGE. No-op if section exists. add_nvchecker_section() { diff --git a/tests/mkhint_test.sh b/tests/mkhint_test.sh index 85d988d..e000820 100755 --- a/tests/mkhint_test.sh +++ b/tests/mkhint_test.sh @@ -1950,6 +1950,30 @@ echo "$arrow_line" | grep -q '0.26.7' && echo "$arrow_line" | grep -q '0.26.8' \ || { echo " FAIL: report versions. out=$rep"; (( FAIL++ )); ERRORS+=("T-BM21"); } rm -f "$MOCK_BASE/manifest_fixture" "$MOCK_HINT/nvim.hint" +# ── T-NV1: _registry_name_from_url extracts names per host ──────────────────── +echo "" +echo "T-NV1: _registry_name_from_url host-specific parsing" +# Build a patched script we can source for unit-testing helpers +SRC_PATCHED=$(mktemp /tmp/mkhint_src_XXXXXX) +sed -e "s|REPO_DIR=\".*\"|REPO_DIR=\"$MOCK_REPO\"|" \ + -e "s|HINT_DIR=\".*\"|HINT_DIR=\"$MOCK_HINT\"|" \ + "$SCRIPT" > "$SRC_PATCHED" +# shellcheck disable=SC1090 +source "$SRC_PATCHED" + +nv_out="$MOCK_BASE/nv_helper.txt" +{ + echo "crates $(_registry_name_from_url 'https://crates.io/api/v1/crates/ripgrep/ripgrep-14.0.0.crate' ripgrep)" + echo "gems $(_registry_name_from_url 'https://rubygems.org/downloads/rails-7.1.0.gem' rails)" + echo "npm $(_registry_name_from_url 'https://registry.npmjs.org/left-pad/-/left-pad-1.3.0.tgz' left-pad)" + echo "fallback $(_registry_name_from_url 'https://example.com/weird/path.tar.gz' mypkg)" +} > "$nv_out" + +assert_contains "crates name parsed" "$nv_out" '^crates ripgrep$' +assert_contains "gems name parsed" "$nv_out" '^gems rails$' +assert_contains "npm name parsed" "$nv_out" '^npm left-pad$' +assert_contains "fallback to PRGNAM" "$nv_out" '^fallback mypkg$' + # ─── SUMMARY ────────────────────────────────────────────────────────────────── teardown |
