radian-software / apheleia

🌷 Run code formatter on buffer contents without moving point, using RCS patches and dynamic programming.
MIT License
547 stars 74 forks source link

Apheleia-npx fails on windows #311

Open JordanAnthonyKing opened 1 month ago

JordanAnthonyKing commented 1 month ago

Firstly, bash needs to be on the path for aphelia to not fail silently, although this is somewhat normal it'd be nice to know it's a requirement.

After adding bash to the path I was hitting an error with the script trying to combine windows and posix style paths:

$ "bash" "c:/Users/jking/.config/emacs/.local/straight/build-30.0.50/apheleia/scripts/formatters/apheleia-npx" "prettier" "--stdin-filepath" "c:/Users/jking/source/XSight/XClient/apps/location/src/app/modules/locations/components/data-providers/data-provider-popup/basic-auth-data-provider/basic-auth-data-provider.component.ts" "--tab-width" "2"

C:\Users\jking\source\XSight\XClient\node_modules\.bin/../node/bin/node: line 1: This: command not found

Command failed with exit code 127.

I fixed it with the following hack for now:

    elif [[ -n ${npm_root} ]]; then
        # trying npm
        node_modules_paths=(\
            $(node -e 'console.log(require.resolve.paths("").map(path => path.replace(/\\/g, "/").join("\n"))'))
        for path in ${node_modules_paths[@]}; do
            echo path
            if [[ -x "${path}/.bin/$1" ]]; then
                exec "${path}/.bin/$1" "${@:2}"
            fi
        done
    fi
raxod502 commented 5 days ago

I've pushed a commit that documents the dependencies explicitly.