madskristensen / JavaScriptPrettier

A Visual Studio extension
Other
158 stars 30 forks source link

Use prettier from the current project instead of the bundled version #16

Closed mderazon closed 6 years ago

mderazon commented 6 years ago

Can this extension first try to see if the current project have prettier installed ? So instead of _installDir we'll look for project dir ?

Prettier versions change the output from time to time and the version that is bundled with the extension might create a different output than the one the user has installed locally in their project

jesperbjensen commented 6 years ago

I think this is a good idea.

I see two ways we could implement this:

  1. Settings page where you can choose to use the bundled version or the one installed in your project
  2. Look for a package.json and then look if prettier is installed - if so - use that.

If someone wants to help out with this one, they are very welcome.

tommck commented 6 years ago

I was thinking of trying to tackle this. So, right now it uses a hard-coded version, but I was thinking of looking solely in the root folder (either where the Project file is, or the root of the open folder) for a node_modules/.bin/prettier.cmd file, and, if we don't find it, just using the default version.

Do you see anything wrong with this approach @jesperbjensen?

P.S. Was also thinking of adding the ability to configure the default version so that it's not hard-coded 1.12.1, but a user-entered default.

jesperbjensen commented 6 years ago

@tommck that would be awesome! 🎉🎊🤴

tommck commented 6 years ago

@jesperbjensen I was thinking of trying to find the prettier.cmd file when the solution/project is initially opened, but I realized that that the solution might have many projects and I might need to have a mapping of project -> prettier.cmd path.

Do you think the speed will suck if I search every time we're running prettier?

jesperbjensen commented 6 years ago

I dont think it will be an issue. Right now we are asking prettier to look for it’s configuration file on each run - and it must walk the directory tree to do this - and we can skip that step if you find the cmd file. So that should equal up.

It must be something like:

  1. find current directory of file
  2. Is there a package.json? 3a. If so - find the cmd in node_modules 3b. If not, move a level up and try again.

If we ever have trouble about speed - then we should be able to cache the result per directory - on demand.

We are really just doing what node does when it parses a file - so it can’t be that slow 🙂

There should be no need to parse the package.json - I don’t even think that node does that - it just looks for the directory.

tommck commented 6 years ago

Alright, it's been a month, but I'm going to start working on this now. Wish me luck :)

tommck commented 6 years ago

So, I have it scanning for a local prettier.

I might add support for checking for a global prettier install, if I can find that

tommck commented 6 years ago

Hmm.. I didn't update the version number

tommck commented 6 years ago

With that PR being merged, this issue should be closed

tommck commented 6 years ago

Hey @madskristensen, since you accepted the PR, could you close this too?

tommck commented 6 years ago

@madskristensen are we planning on publishing a new version soon?

Actually, it's not important to me. I really want to have #6 done before I can really use it anyway :) I'm still working on that

madskristensen commented 6 years ago

I can release a new version as soon as I get back from paternity leave. It'll be the same version as the CI build so just use that for now

tommck commented 6 years ago

Thanks for answering things on paternity leave. Totally unnecessary. Also: Congratulations! :)

Maybe we can coordinate a few things when you get back?