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
Create prettier.config.js with some initial settings
Format via prettierd
Modify prettier.config.js
Format again via prettierd
Expected behavior:
Code is formatted with settings from latest configuration.
Actual behavior:
Configuration changes are ignored and code is formatted with previous settings.
Details:
prettierd is a plugin that keeps prettier as a long lived process and calls format on running instances.
It first pulls the configuration using resolveConfig then calls format with this configuration.
However, despite using the useCache: false setting to pickup any changes to the configuration, when the configuration is written in JavaScript changes do not get picked up.
Which uses import to load the configuration associated with the file.
However import itself has a cache within Node. Though I'm not too familiar with the details of import caching I believe this will result in the same response until the process is restarted. I've created a similar issue in prettierd to see if there is some way around this on the client side: fsouza/prettierd#719.
There really doesn't seem to be a good way to handle reloading a module via an import statement in JavaScript. I implemented and tested a "functional" solution locally based on some discussion from here: nodejs/node#49442.
It relies on some odd behavior where the query part of the path doesn't change what actually gets imported, but will cause a cache miss so Node will reload the module.
This has its own drawbacks such as memory leaking, while old "versions" will not be retrieved, since they are still referenced in some internal cache they never get cleaned up. As well as just being very unintuitive.
The text was updated successfully, but these errors were encountered:
Environments:
prettierd
Steps to reproduce:
prettier.config.js
with some initial settingsprettierd
prettier.config.js
prettierd
Expected behavior:
Code is formatted with settings from latest configuration.
Actual behavior:
Configuration changes are ignored and code is formatted with previous settings.
Details:
prettierd is a plugin that keeps
prettier
as a long lived process and calls format on running instances.It first pulls the configuration using
resolveConfig
then callsformat
with this configuration.However, despite using the
useCache: false
setting to pickup any changes to the configuration, when the configuration is written in JavaScript changes do not get picked up.From looking at the code to load a JavaScript configuration I think the issue stems from this function: https://github.com/prettier/prettier/blob/main/src/config/prettier-config/loaders.js#L20
Which uses
import
to load the configuration associated with the file.However
import
itself has a cache within Node. Though I'm not too familiar with the details of import caching I believe this will result in the same response until the process is restarted. I've created a similar issue in prettierd to see if there is some way around this on the client side: fsouza/prettierd#719.There really doesn't seem to be a good way to handle reloading a module via an import statement in JavaScript. I implemented and tested a "functional" solution locally based on some discussion from here: nodejs/node#49442.
It relies on some odd behavior where the query part of the path doesn't change what actually gets imported, but will cause a cache miss so Node will reload the module.
This has its own drawbacks such as memory leaking, while old "versions" will not be retrieved, since they are still referenced in some internal cache they never get cleaned up. As well as just being very unintuitive.
The text was updated successfully, but these errors were encountered: