You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Use prettier from the current project instead of the bundled version #16
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
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 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?
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:
find current directory of file
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.
Activity
jesperbjensen commentedon May 22, 2018
I think this is a good idea.
I see two ways we could implement this:
If someone wants to help out with this one, they are very welcome.
tommck commentedon Jun 11, 2018
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 commentedon Jun 12, 2018
@tommck that would be awesome! 🎉🎊🤴
tommck commentedon Jun 12, 2018
@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 commentedon Jun 12, 2018
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:
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 commentedon Jul 14, 2018
Alright, it's been a month, but I'm going to start working on this now. Wish me luck :)
tommck commentedon Jul 14, 2018
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 commentedon Jul 14, 2018
Hmm.. I didn't update the version number
Merge pull request #21 from tommck/master
tommck commentedon Jul 15, 2018
With that PR being merged, this issue should be closed
tommck commentedon Jul 17, 2018
Hey @madskristensen, since you accepted the PR, could you close this too?
tommck commentedon Jul 25, 2018
@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 commentedon Jul 25, 2018
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 commentedon Jul 26, 2018
Thanks for answering things on paternity leave. Totally unnecessary.
Also: Congratulations! :)
Maybe we can coordinate a few things when you get back?