Last active
April 22, 2026 22:03
-
-
Save mortenson/05841a6f15f6cf2db496022a98afe67a to your computer and use it in GitHub Desktop.
Automatically configure npm, pnpm, and yarn to have 7-day release cooldown for all macOS users
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /bin/bash | |
| set -e | |
| for USER_HOME in /Users/*/; do | |
| USERNAME=$(basename "$USER_HOME") | |
| case "$USERNAME" in | |
| Shared|.localized|Guest) continue ;; | |
| esac | |
| [ -d "${USER_HOME}Library" ] || continue | |
| USER_UID=$(stat -f %u "$USER_HOME") | |
| USER_GID=$(stat -f %g "$USER_HOME") | |
| # npm | |
| USER_NPMRC="${USER_HOME}.npmrc" | |
| echo "Configuring ~/.npmrc for ${USERNAME} ..." | |
| # Remove min-release-age from npmrc if it exists | |
| if [ -f "$USER_NPMRC" ]; then | |
| grep -v "^min-release-age=" "$USER_NPMRC" > "${USER_NPMRC}.tmp" || true | |
| mv "${USER_NPMRC}.tmp" "$USER_NPMRC" | |
| fi | |
| EXISTING="" | |
| [ -f "$USER_NPMRC" ] && EXISTING=$(cat "$USER_NPMRC") | |
| printf "min-release-age=7\n%s" "$EXISTING" > "$USER_NPMRC" | |
| chown "${USER_UID}:${USER_GID}" "$USER_NPMRC" | |
| chmod 644 "$USER_NPMRC" | |
| # pnpm | |
| USER_PNPM_DIR="${USER_HOME}Library/Preferences/pnpm/" | |
| USER_PNPM_RC="${USER_PNPM_DIR}rc" | |
| echo "Configuring ~/Library/Preferences/pnpm/rc for ${USERNAME} ..." | |
| mkdir -p "${USER_PNPM_DIR}" | |
| # Remove minimum-release-age from pnpm/rc if it exists | |
| if [ -f "$USER_PNPM_RC" ]; then | |
| grep -v "^minimum-release-age=" "$USER_PNPM_RC" > "${USER_PNPM_RC}.tmp" || true | |
| mv "${USER_PNPM_RC}.tmp" "$USER_PNPM_RC" | |
| fi | |
| EXISTING="" | |
| [ -f "$USER_PNPM_RC" ] && EXISTING=$(cat "$USER_PNPM_RC") | |
| printf "minimum-release-age=10080\n%s" "$EXISTING" > "$USER_PNPM_RC" | |
| chown "${USER_UID}:${USER_GID}" "$USER_PNPM_RC" | |
| chmod 644 "$USER_PNPM_RC" | |
| # yarn | |
| USER_YARNRC="${USER_HOME}.yarnrc.yml" | |
| echo "Configuring ~/.yarnrc.yml for ${USERNAME} ..." | |
| # Remove npmMinimalAgeGate from npmrc if it exists | |
| if [ -f "$USER_YARNRC" ]; then | |
| grep -v "^npmMinimalAgeGate" "$USER_YARNRC" > "${USER_YARNRC}.tmp" || true | |
| mv "${USER_YARNRC}.tmp" "$USER_YARNRC" | |
| fi | |
| EXISTING="" | |
| [ -f "$USER_YARNRC" ] && EXISTING=$(cat "$USER_YARNRC") | |
| printf "npmMinimalAgeGate: 10080\n%s" "$EXISTING" > "$USER_YARNRC" | |
| chown "${USER_UID}:${USER_GID}" "$USER_YARNRC" | |
| chmod 644 "$USER_YARNRC" | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment