Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Prettier config JS file changes ignored #719

Open
MeanderingProgrammer opened this issue Apr 26, 2024 · 3 comments
Open

Prettier config JS file changes ignored #719

MeanderingProgrammer opened this issue Apr 26, 2024 · 3 comments

Comments

@MeanderingProgrammer
Copy link

MeanderingProgrammer commented Apr 26, 2024

After the initial load in a workspace, changing a JavaScript prettier config has no impact and requires restarting prettierd.

After looking through the code, I believe this is due to how Node caches imports and how prettier handles the resolveConfig method call.

Even though useCache: false should result in the configuration being reloaded looking through the prettier implementation when a JS config is reloaded it makes this method call: https://github.com/prettier/prettier/blob/main/src/config/prettier-config/loaders.js#L20

async function loadJs(file) {
  const module = await import(pathToFileURL(file).href);
  return module.default;
}

Since the file path is the same on reload the Node import caching behavior will return the same configuration as before.

Though I am not very familiar with import caching, that is my understanding from reading: https://nodejs.org/api/modules.html#caching.

This may be something that needs to be fixed on prettier's side, at least if my understanding is correct. I've created an issue there as well: prettier/prettier#16234.

I am unsure if there is something that can be done on this side. Using non JS configurations works as expected since files are re-read and re-parsed by prettier.

May just be something to be aware and mark as a note.

@MeanderingProgrammer
Copy link
Author

As a patch in Neovim I added the following auto command to restart prettierd on config changes:

vim.api.nvim_create_autocmd({ 'BufWritePost' }, {
    group = vim.api.nvim_create_augroup('RestartPrettierd', { clear = true }),
    pattern = '*prettier*',
    callback = function()
        vim.fn.system('prettierd restart')
    end,
})

@thekaganugur
Copy link

As a patch in Neovim I added the following auto command to restart prettierd on config changes:

vim.api.nvim_create_autocmd({ 'BufWritePost' }, {
    group = vim.api.nvim_create_augroup('RestartPrettierd', { clear = true }),
    pattern = '*prettier*',
    callback = function()
        vim.fn.system('prettierd restart')
    end,
})

This is a really cool solution. Thanks! :)

@Glup3
Copy link

Glup3 commented Jun 17, 2024

As a patch in Neovim I added the following auto command to restart prettierd on config changes:

vim.api.nvim_create_autocmd({ 'BufWritePost' }, {
    group = vim.api.nvim_create_augroup('RestartPrettierd', { clear = true }),
    pattern = '*prettier*',
    callback = function()
        vim.fn.system('prettierd restart')
    end,
})

Thank you very much for this fix!

scan-lan pushed a commit to scan-lan/dotfiles that referenced this issue Aug 22, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants