cli icon indicating copy to clipboard operation
cli copied to clipboard

Support local installations of beautifiers

Open stevenzeck opened this issue 6 years ago • 9 comments

From @cdfa on December 11, 2018 13:49

Is your feature request related to a problem? Please describe. Yes, I was trying to get this working for a project where in which the dev-dependencies state everything I'm using to develop the project except for editor specific stuff, but unibeautify seems to be unable to find beautifiers (like beautifier-js-beautify) when they are installed locally.

Describe the solution you'd like Support locally installed beautifiers.

Describe alternatives you've considered

  • Having the beautifiers globally installed, but the other stuff locally, with a comment in the package.json saying the beautifiers need to be installed globally.

Additional context

Copied from original issue: Unibeautify/unibeautify#213

stevenzeck avatar Dec 12 '18 18:12 stevenzeck

@cdfa are you using the CLI, VSCode plugin or just calling it via Node?

stevenzeck avatar Dec 12 '18 18:12 stevenzeck

From @cdfa on December 12, 2018 0:14

I was using the cli. When it's installed locally, I can run it with npx unibeautify.

stevenzeck avatar Dec 12 '18 18:12 stevenzeck

OK, yes, the CLI only looks for globally installed beautifiers via g-search, then loads them via requireg. It would be an enhancement to add support for local installations.

stevenzeck avatar Dec 12 '18 18:12 stevenzeck

Applicable code:

https://github.com/Unibeautify/unibeautify-cli/blob/master/src/utils.ts#L3-L20

https://github.com/Unibeautify/unibeautify/blob/master/src/DependencyManager/NodeDependency.ts#L40-L52

It may require a change to Unibeautify core at https://github.com/Unibeautify/unibeautify/blob/master/src/DependencyManager/NodeDependency.ts#L44-L46 as well as CLI to search for global in addition to local.

Pull Requests very welcome!

Glavin001 avatar Dec 12 '18 22:12 Glavin001

@Glavin001 is there a package out there that searches or lists locally installed packages? I can't seem to find one.

stevenzeck avatar Dec 13 '18 00:12 stevenzeck

@stevenzeck Anything in https://github.com/prettier/prettier/blob/master/src/common/load-plugins.js look helpful?

Glavin001 avatar Dec 13 '18 03:12 Glavin001

@stevenzeck or https://github.com/yeoman/environment/blob/f9468481911c31673378b38e63872f57a1163f38/lib/resolver.js#L63 ?

Glavin001 avatar Dec 13 '18 03:12 Glavin001

Not really. Looking for something like this, only it searches in local: https://github.com/TremayneChrist/npm-g-search. Guess we could borrow that code and modify it to our needs...

stevenzeck avatar Dec 13 '18 03:12 stevenzeck

Is running npx list <pkg-name> out of the question? Otherwise, looking at the way npx does it might be helpful.

cdfa avatar Jan 02 '19 20:01 cdfa