Skip to content

[Enhancement] automatic prettier_cli_path resolution #305

@sanekb

Description

@sanekb

Is your feature request related to a problem?

It's hard to call it both a feature and a bug. It's more like something in between.

Since Deno and Bun can install dependencies in node_modules themselves, there's a small problem with automatic resolution of prettier_cli_path (when it's set to empty) on Windows.

It's all about file extensions in .bin folders, each package manager creates its own versions:

  • npm
    • Local & Global: prettier, prettier.cmd, prettier.ps1
  • deno
    • Local: prettier.cmd
    • Global: prettier, prettier.cmd
  • bun
    • Local & Global: prettier.bunx, prettier.exe
# def resolve_prettier_cli_path, sthelper.py#L164

def make_local_prettier_path(somepath):
    return os.path.join(somepath, 'node_modules', '.bin', 'prettier')

...

# 1. check for prettier installed relative to active view
active_view_parents = generate_dirs(os.path.dirname(view.file_name()), limit=500)
for parent in active_view_parents:
    closest_to_view_prettier = make_local_prettier_path(parent)
    if os.path.exists(closest_to_view_prettier):    # deno and bun will not be found
        return closest_to_view_prettier
# def resolve_prettier_cli_path, sthelper.py#L196

# 4. check globally install prettier
prettier_cmd = 'prettier'
if is_windows():
    prettier_cmd = ensure_file_has_ext(prettier_cmd, ".cmd")    # bun will not be found
return which(prettier_cmd)

Describe the solution you'd like

Perhaps this should be a subresolve function in util.py, working similarly to os.path.exists and which, but with an optional array of all extensions for Windows.

Additional context or screenshots

No response

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions