yarn icon indicating copy to clipboard operation
yarn copied to clipboard

yarn incorrectly uses $XDG_DATA_HOME for `linkFolder`

Open asottile-sentry opened this issue 1 year ago • 1 comments

yarn's default for linkFolder is in the default for $XDG_CONFIG_HOME:

$ yarn config current | grep linkFolder
  "linkFolder": "/Users/asottile/.config/yarn/link",

the default for XDG_CONFIG_HOME is ~/.config

applying XDG_DATA_HOME changes the value of linkFolder even if XDG_DATA_HOME is set to the default:

$ XDG_DATA_HOME=$HOME/.local/share yarn config current | grep linkFolder
  "linkFolder": "/Users/asottile/.local/share/yarn/link",

this appears to be two bugs -- fixing either would resolve this:

  • https://github.com/yarnpkg/yarn/blob/158d96dce95313d9a00218302631cd263877d164/src/constants.js#L63 (this is using the data home as the joined value for linkFolder)
  • https://github.com/yarnpkg/yarn/blob/158d96dce95313d9a00218302631cd263877d164/src/util/user-dirs.js#L22 getDataDir falls back to ~/.config

asottile-sentry avatar Jan 24 '24 16:01 asottile-sentry

Good point, and in fact there's a comment in the code that alludes to this:

https://github.com/yarnpkg/yarn/blob/158d96dce95313d9a00218302631cd263877d164/src/util/user-dirs.js#L19-L21

I think the old fallback was kept for backwards compatibility.

The XDG spec says:

$XDG_DATA_HOME defines the base directory relative to which user-specific data files should be stored. If $XDG_DATA_HOME is either not set or empty, a default equal to $HOME/.local/share should be used.

So it should be falling back to .local/share/yarn/link.

Daniel15 avatar May 24 '24 22:05 Daniel15