Skip to content

Commit adebc9a

Browse files
committed
fix(publish): improve Windows compatibility for npm token handling in publish script
1 parent 70df5a4 commit adebc9a

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

scripts/publish-latest.sh

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,29 @@ fi
5454
if [ -n "${NPM_PUBLISH_TOKEN:-}" ]; then
5555
echo "🔑 Found NPM_PUBLISH_TOKEN in .env"
5656

57-
# create temp npmrc
58-
TEMP_NPMRC=$(mktemp)
59-
echo "//registry.npmjs.org/:_authToken=${NPM_PUBLISH_TOKEN}" > "$TEMP_NPMRC"
57+
# Use a local file for compatibility with Windows npm (avoids /tmp path issues)
58+
TEMP_NPMRC_NAME=".npmrc-publish-temp"
59+
echo "//registry.npmjs.org/:_authToken=${NPM_PUBLISH_TOKEN}" > "$TEMP_NPMRC_NAME"
60+
61+
# Determine the path format for the environment variable
62+
if command -v cygpath >/dev/null 2>&1; then
63+
# Git Bash on Windows - convert to Windows path for the env var
64+
TEMP_NPMRC=$(cygpath -w "$PWD/$TEMP_NPMRC_NAME")
65+
else
66+
# Standard - use absolute unix path
67+
TEMP_NPMRC="$PWD/$TEMP_NPMRC_NAME"
68+
fi
6069

61-
# Validate token
62-
if ! npm whoami --userconfig "$TEMP_NPMRC" >/dev/null 2>&1; then
70+
# Validate token (using local file name for bash command to be safe)
71+
if ! npm whoami --userconfig "$TEMP_NPMRC_NAME" >/dev/null 2>&1; then
6372
echo "❌ Error: The NPM_PUBLISH_TOKEN in .env is invalid or expired." >&2
6473
echo " Please regenerate the token." >&2
6574
exit 1
6675
fi
6776

68-
echo "✅ Token validated. User: $(npm whoami --userconfig "$TEMP_NPMRC")"
77+
echo "✅ Token validated. User: $(npm whoami --userconfig "$TEMP_NPMRC_NAME")"
78+
79+
# Export the OS-appropriate path for the sub-process
6980
export NPM_CONFIG_USERCONFIG="$TEMP_NPMRC"
7081

7182
else

0 commit comments

Comments
 (0)