fix: auto-patch Commander.js multi-char short flags in postinstall

The source uses -d2e flag which Commander.js rejects (single-char only).
postinstall.sh now patches both:
1. shortFlagExp regex: /^-[^-]$/ → /^-[^-]+$/
2. single-char restriction check disabled

Users no longer need to manually patch node_modules after bun install.
This commit is contained in:
Roger
2026-04-01 10:16:20 +08:00
parent 5ea0b188f5
commit 2a862bb2bd

View File

@@ -117,3 +117,13 @@ STUBEOF
fi
echo "[postinstall] Stubs created."
# ── Patch Commander.js for multi-char short flags ───────────────────────────
OPTION_JS=$(find node_modules -path "*/commander/lib/option.js" -type f | head -1)
if [ -n "$OPTION_JS" ]; then
# Patch 1: shortFlagExp — allow one or more chars after dash
sed -i "s|shortFlagExp = /\^-\\[^-\\]\\$/|shortFlagExp = /\^-[^-]+\$/|" "$OPTION_JS"
# Patch 2: disable single-char short flag restriction
sed -i "s|if (/\\^-\\[^-\\]\\[^-\\]/.test(unsupportedFlag))|if (false)|" "$OPTION_JS"
echo "[postinstall] Patched Commander.js for multi-char short flags"
fi