Dependency on old minimum dot-properties version results in inconsistent cross-machine formatting
This has "^1.0.0" as its minimum dot-properties version. Version 1.0.2 of it introduced a feature to "Start lines that need folding on a new line". Therefore, depending on NPM configuration and what other packages are already installed, one computer may get this feature applied and another may not. There may also be other formatting behavior differences, but that's the one I've noticed in practice.
Yes, but the plugin still works fine with any version in the range, yes?
If you need to ensure the same behaviour on multiple machines, you could include an exact dot-properties dependency in your app's package.json, which would then be used by the plugin everywhere.
I did include an exact dot-properties dependency, as a workaround, in this case in my Gradle build configuration for Spotless.
However, an end-user is going to expect this plugin to format their .properties files in a consistent manner regardless of the exact circumstances/state in which they install the latest version of prettier-plugin-properties.
As it is now:
-
If I already had
dot-properties1.0.1 or earlier in my user-wide node_modules (~/node_modules), and I simply didnpm install prettier-plugin-propertiesfrom my home directory, I would get properties files without the initial line breaks when using~/node_modules/.bin/prettier. -
A Mac user in my company, for whatever reason, when using the Spotless Gradle plugin, in a modern version of Gradle Wrapper, with dependencies explicitly on
prettier-plugin-properties0.3.0 andprettier3.4.2, from a state with no Gradle caches whatsoever (~/.gradleand<project_dir>/.gradledeleted), ultimately ended up withdot-properties1.1.0, leading to him having the initial line breaks on long lines. On my machine, running Arch Linux, with all else being equal, it consistently installsdot-properties1.0.0, leading to me not having the initial line breaks on long lines. (EDIT: Caused by~/.npmcache differences, see below).
Could you clarify how Gradle is relevant here? Does it somehow manage JS dependencies as well?
EDIT: I wiped most of this message, as it turned out to not be very relevant.
Yes. The Spotless plugin for Gradle installs its own NPM dependencies, for Prettier and other kinds of tasks, inside the Gradle project's build directory.
After some further experimenting, I determined that what I thought was inconsistent behavior between Arch Linux and Mac was really that I just didn't understand that `~/.npm" is the user-wide NPM download cache directory, and I believe my computer had been installing the old version from its contents.
Simple reproduction of the basic problem:
Good output:
-
docker run -it node:23.6.1-bookworm bash -
cd ~ npm install prettier-plugin-properties echo 'something=this is an extremely long entry. this is an extremely long entry.this is an extremely long entry. this is an extremely long entry.' | node_modules/.bin/prettier --with-node-modules --plugin prettier-plugin-properties --parser dot-properties
Bad output:
-
docker run -it node:23.6.1-bookworm bash -
cd ~ npm install [email protected] npm install prettier-plugin-properties echo 'something=this is an extremely long entry. this is an extremely long entry.this is an extremely long entry. this is an extremely long entry.' | node_modules/.bin/prettier --with-node-modules --plugin prettier-plugin-properties --parser dot-properties
In your post above the "bad output" is achieved with an explicit dot-properties dependency. Isn't that working exactly as intended, i.e. you're selecting a specific version of the package to use, and thereby selecting the exact output?
In an environment where you want to ensure that the behaviour of prettier-plugin-properties is replicable on multiple machines, don't you need to define its exact version in something like a package.json file? And in that same place, can't you also define an exact dot-properties version?
In my "bad output" example, I'm not specifying a version of the dot-properties module for prettier-plugin-properties to use as its dependency, but rather I'm showing how the behavior of prettier-plugin-properties is when used in an environment where an older version of dot-properties had previously been installed. Those are not the same thing.
I can indeed specify a version of dot-properties right alongside any place where I use prettier-plugin-properties, and that will cause places I configure to have consistent formatting in this regard. However, I consider that a workaround. dot-properties, unless I have code that directly uses it, is a transitive dependency rather than a direct dependency. The behavior of a direct dependency at a given version should not generally be significantly affected by the version of a transitive dependency it pulls in. Especially in the context of Prettier, having the stated design goal that it, "enforces a consistent code style (i.e. code formatting that won’t affect the AST) across your entire codebase", that it is a tool to help people avoid conflicts or commits back and forth just about styling, etc., it's quite important that a given version of a Prettier plugin format code in a consistent style, without versions of transitive dependencies being explicitly specified.
If this issue of the leading line break on long entries is the only difference you're aware of between using your plugin with dot-properties 1.0.0 and using it with dot-properties 1.1.0, and because this line break behavior change was introduced with dot-properties 1.0.2, my recommendation is that you change your dependency version for it to either ^1.0.2 or >=1.0.2.