-
-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cache directory respects XDG_CACHE_HOME (basedir spec) #214
Conversation
I'm unsure what is going on with the tests. I get the same test failures locally when run from master. |
@jasonkarns I am seeing similar on updates to #194 just now. The same tests fail for me locally, and also when I run them from the tip of master. |
While I do really like this I am a bit concerned by
Maybe this should be using |
@toddbluhm Personally, I don't agree with "You should not use XDG on macOS and Windows.". I'm on macOS and have been using XDG's locations for years. I might agree for tools and apps that are built for non-developers. In that case, it makes sense to put data in ~/Library/** as per the apple reference guidelines. However, for developers who spend all day in Terminal, and likely have a dotfiles repo for versioning their configs, and use whole piles of *nix tools, I strongly strongly favor XDG's structure. Windows, eh, I have no strong opinion. Though I would wager with the prevalence of git-bash, and WSL that even there, developer-focused tools should remain consistent with the XDG directories. (All the XDG defaults still live in $HOME, anyway, so XDG still works on Windows just fine.) |
@jasonkarns Thank you for that clarification. I do agree that since this is a developer tool it makes sense to keep the location in the respective @mightyiam you still okay with this change since you responded on the initial ticket? @LinusU thoughts? I am thinking this will probably require a major version change since it changes the cache location for all platforms. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Major change.
@@ -7,7 +7,7 @@ var os = require('os') | |||
var path = require('path') | |||
var pkgConf = require('pkg-conf') | |||
|
|||
var HOME_OR_TMP = os.homedir() || os.tmpdir() | |||
var CACHE_HOME = require('xdg-basedir').cache || os.tmpdir() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Just the one comment and a rebase and we can move forward on this.
Co-authored-by: Linus Unnebäck <[email protected]>
Rebased! |
@@ -38,8 +38,8 @@ function Linter (opts) { | |||
var m = opts.version && opts.version.match(/^(\d+)\./) | |||
var majorVersion = (m && m[1]) || '0' | |||
|
|||
// Example cache location: .standard-v12-cache/ | |||
var cacheLocation = path.join(HOME_OR_TMP, `.${this.cmd}-v${majorVersion}-cache/`) | |||
// Example cache location: ~/.cache/standard/v12/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest this comment be removed. It may be understood that that is the only possible pattern.
// Example cache location: ~/.cache/standard/v12/ |
When merging, squash merge into a single commit? |
Released as 13.0.0 |
What is the purpose of this pull request? (put an "X" next to item)
[ ] Documentation update
[ ] Bug fix
[x] New feature
[ ] Other, please explain:
What changes did you make? (Give an overview)
Instead of setting the cacheLocation to a directory in the user
$HOME
, this PR now respects the XDG Basedir Specification (specifically theXDG_CACHE_HOME
environment variable).Which issue (if any) does this pull request address?
fixes standard/standard#1501
Is there anything you'd like reviewers to focus on?
The XDG Basedir spec states that
XDG_CACHE_HOME
should be used (if set) to determine where to write cache files. It is recommended and conventional that tools create a self-named directory beneath cache-home for the files to live in. If theXDG_CACHE_HOME
is empty or unset, a value of$HOME/.cache
is used. (TMPDIR
is used ifHOME
is unset/empty) Additionally, to mirror the existing support for storing multiple caches, a subdirectory for each major version is used beneath the linter's cache directory. (${XDG_CACHE_HOME:-$HOME/.cache}/standard/vX
)xdg-basedir is a package by sindresorhus which derives the appropriate values for the different XDG directories according to the spec (and respecting the fallback values). This package derives these values only once, when required. Because the values are cached, it is non-trivial to write tests to cover the various env-var scenarios. Due to this and the simplicity of the code change, I opted to not add any tests to the existing (simple) suite.
In place of tests, here are the various scenarios covered manually:
XDG_CACHE_HOME
configured to a custom location:$ XDG_CACHE_HOME=/my/cache node -p "new require('./').linter({cmd: 'linty', eslint: require('eslint')}).eslintConfig.cacheLocation" /my/cache/linty/v0/
XDG_CACHE_HOME
is unset or empty; (uses the XDG default:$HOME/.cache/
)$ XDG_CACHE_HOME= node -p "new require('./').linter({cmd: 'linty', eslint: require('eslint')}).eslintConfig.cacheLocation" /Users/jasonkarns/.cache/linty/v0/
XDG_CACHE_HOME
is unset or empty andHOME
is unset or empty; (uses TMPDIR):$ TMPDIR=/tempy HOME= XDG_CACHE_HOME= node -p "new require('./').linter({cmd: 'linty', eslint: require('eslint')}).eslintConfig.cacheLocation" /tempy/linty/v0/