Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ function generateShShim (src: string, to: string, opts: InternalOptions): string

let sh = `\
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')")
basedir=$(dirname "$(realpath "$0" | sed -e 's,\\\\,/,g')")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the realpath command available on all supported systems?

can this be fixed in https://github.com/pnpm/pnpm/tree/main/pkg-manager/link-bins instead?

Copy link
Author

@baymer baymer Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, some system may have no realpath.
May be we can use something like this?

get_path() {
    if command -v realpath >/dev/null 2>&1; then
        realpath "$1"
    elif command -v readlink >/dev/null 2>&1; then
        # some systems has readlink, but doesn't have "-f" flag
        if readlink -f "$1" >/dev/null 2>&1; then
            readlink -f "$1"
        else
             readlink "$1"
        fi
    elif command -v perl >/dev/null 2>&1; then
        perl -e 'use Cwd "abs_path"; print abs_path(shift)' "$1"
    elif [[ $1 = /* ]]; then
        echo "$1"
    else 
        echo "$PWD/${1#./}"
    fi
}

basedir=$(dirname "$(get_path "$0" | sed -e 's,\\\\,/,g')")

or

basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')")

case \`uname\` in
    *CYGWIN*|*MINGW*|*MSYS*)
        if command -v cygpath > /dev/null 2>&1; then
            basedir=\`cygpath -w "$basedir"\`
        fi
    ;;
    *)
      if command -v realpath >/dev/null 2>&1; then
          basedir=`realpath "$basedir"`
      elif command -v readlink >/dev/null 2>&1; then
          # some systems has the readlink, but doesn't have "-f" flag
          if readlink -f "$basedir" >/dev/null 2>&1; then
               basedir=`readlink -f "$basedir"`
          else
               basedir=`readlink "$basedir"`
          fi
      elif command -v perl >/dev/null 2>&1; then
          basedir=`perl -e 'use Cwd "abs_path"; print abs_path(shift)' "$basedir"`
      elif [[ $basedir != /* ]]; then
          basedir="$PWD/${basedir#./}"
      fi
    ;;
esac

Copy link
Author

@baymer baymer Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be fixed in https://github.com/pnpm/pnpm/tree/main/pkg-manager/link-bins instead?

I think we can't, because it can broke portable resource (build+node_modules).
So we cannot calculate it in the compile time. We can calculate it only in the runtime.


case \`uname\` in
*CYGWIN*|*MINGW*|*MSYS*)
Expand Down