Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embedded elm-format is not found in globally installed plugin #1

Closed
kachkaev opened this issue Mar 24, 2018 · 3 comments
Closed

Embedded elm-format is not found in globally installed plugin #1

kachkaev opened this issue Mar 24, 2018 · 3 comments

Comments

@kachkaev
Copy link
Member

kachkaev commented Mar 24, 2018

Calling a bult-in elm-format binary fails when prettier-plugin-elm is installed globally. We need a slightly improved search mechanism for node_modules/.bin/elm-format in order to fix this. A temporary workaround involves installing elm-format in parallel to the plugin:

npm install --global prettier-plugin-elm elm-format
## or
yarn global add prettier-plugin-elm elm-format

(or elm-format@exp)

@avh4
Copy link

avh4 commented Mar 26, 2018

I tried to make guidelines for plugins to follow (avh4/elm-format#104), which currently says the following:

  • Configuration
    • If the path to elm-format has not be explicitly specified by the user, the plugin should automatically find elm-format if it is located on the $PATH or in /usr/local/bin/.

      Is there an equivalent of /usr/local/bin/ for Windows?

      We should also add the path where npm install -g installs to, since this is the most common issue people have with plugin installation

    • If elm-format is not found, a message should be shown including a link to the elm-format installation instructions ( https://github.com/avh4/elm-format#installation- ). The message will be shown on the plugin settings screen if such a screen exists, and any time the user explicitly tries to format a file. The message may also be shown when the plugin is first installed or when saving an elm file.

I guess it needs to be updated to include a standard way for searching for elm-format installed with npm install -g, as you've noted. (Thought won't things installed that way generally be on the user's $PATH?)

@kachkaev
Copy link
Member Author

kachkaev commented Mar 26, 2018

Thanks for sharing the link @avh4!

When elm-format is installed globally via npm install --global elm-format, everything works fine. The case I'm mentioning in this issue is when you only run npm install --global prettier-plugin-elm, which in turn downloads and installs elm-format as its dependency to /usr/local/lib/node_modules/elm-format/. Unlike in local setups, there is no /usr/local/lib/node_modules/.bin folder, so spawning elm-format only involves a search in /usr/local/bin. This folder does not contain elm-format, because it has a status of a sub-dependency and npm decides not to pollute my global path with its binary.

Alternatively, I could move elm-format to peerDependencies and ask people to explicitly install it every time. But I guess it's better to keep this dependency tightly coupled with prettier-plugin-elm so save someone from using incompatible version pairs.

@kachkaev
Copy link
Member Author

I believe this has been fixed in 6adc859, so there is no more need to install elm-format globally in order to make prettier-plugin-elm work.

Globally installed prettier still fails to load plugins due to prettier/prettier#4000, however, it is possible to install my fork while we are waiting for a new version that includes prettier/prettier#4192.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants