yeoman / update-notifier

Update notifications for your CLI app
BSD 2-Clause "Simplified" License
1.76k stars 132 forks source link

Better adhere to XDG specification #180

Open skipkayhil opened 4 years ago

skipkayhil commented 4 years ago

Spec for reference

Currently, any package that uses update-notifier results in an update-notifier-<package>.json being put in $XDG_CONFIG_HOME.

As someone who symlinks my $XDG_CONFIG_HOME into my dotfiles repository, this leads to undesired behavior. These are not files that I want in my dotfiles, nor do I think they would be useful to keep in sync across multiple devices. I believe the data stored here would be more appropriate in $XDG_DATA_HOME or $XDG_CACHE_HOME

sindresorhus commented 4 years ago

I agree. Should be “data”, not “cache”.

skipkayhil commented 4 years ago

I can create a PR for this, do you have a recommended way to do it? The simplest is probably passing in the new configPath to configstore.

jmromer commented 3 years ago

This would be a welcome addition. I think XDG_STATE_HOME would make more sense, however, since this data isn't portable across machines (as would be expected with XDG_DATA_HOME), but also isn't entirely non-essential (as with XDG_CACHE_HOME):

The $XDG_STATE_HOME contains state data that should persist between (application) restarts, but that is not important or portable enough to the user that it should be stored in $XDG_DATA_HOME. It may contain:

actions history (logs, history, recently used files, …)

current state of the application that can be reused on a restart (view, layout, open files, undo history, …)

{
    "optOut": false,
    "lastUpdateCheck": 1634843835359,
    "update": {
        "latest": "8.1.0",
        "current": "6.14.11",
        "type": "major",
        "name": "npm"
    }
}

There's a node library that abstracts away most of the logic: https://www.npmjs.com/package/xdg-basedir

Happy to submit a PR for this if there's still support for it.

import {xdgData, xdgConfig, xdgDataDirectories} from 'xdg-basedir';

console.log(xdgData);
//=> '/home/sindresorhus/.local/share'

console.log(xdgConfig);
//=> '/home/sindresorhus/.config'

console.log(xdgDataDirectories);
//=> ['/home/sindresorhus/.local/share', '/usr/local/share/', '/usr/share/']