Closed reykjalin closed 3 years ago
I prefer adding a configuration option at both the Nova and project levels. The reason for the strict name check is because e.g. prettier plugins would otherwise also trigger the check.
The reason for the strict name check is because e.g. prettier plugins would otherwise also trigger the check.
Ah yeah, that makes sense. In that case being able to specify a custom path is perfectly fine by me 🙂
The latest version (v2.3.0) now allows you to set the path to the module in the project settings (as well as a default in the extension settings). Let me know if it works well for you!
Works flawlessly, thank you! 🥇
I like using Automattic/wp-prettier for my projects because of the additional formatting rules it provides, in particular adding spaces inside parentheses and around function arguments. It's a fork of prettier with some additional options available for use in the
.prettierrc
.I also have to use
wp-prettier
at work, so the extension unfortunately doesn't work for my work projects.The way the extension currently looks for a prettier installation doesn't work however, even though
wp-prettier
is installed in place of prettier vianpm i -D 'prettier@npm:wp-prettier@latest'
.The output of
npm ls prettier --parseable --long --depth 0
with the installation like that results in a path like this:<path_to_project>/node_modules/prettier:wp-prettier@2.2.1-beta-1
. Thewp-prettier
part here fails the!name.startsWith('prettier')
check here:https://github.com/alexanderweiss/nova-prettier/blob/91588368b760ae301f028a1f3a8b588a41d313dc/src/Scripts/prettier-installation.js#L19
and thus the extension can't find the
prettier
installed in the project despitewp-prettier
being installed in place:Proposed solutions
Hard-coding an additional check for
wp-prettier
doesn't seem very extendable, but maybe making the check more flexible would be appropriate? Instead of checking forname.startsWith('prettier')
, maybe instead check for if thepath
variable ends withprettier
? Or even just aname.contains('prettier')
although that check may be a bit too lax.An alternative solution that sort of bypasses this problem entirely would be to add an option that allows you to specify a direct path to the prettier directory or even a script that will run prettier for you. That way you could configure the extension to use a global installation of prettier for example.