It's not ideal to set XDG_RUNTIME_DIR in your shell environment,
rather than from your session manager (or systemd, or whatever), since
then you can't reliably provide the same lifetime guarantees that
XDG_RUNTIME_DIR is supposed to have? But this is still preferable to not
having an XDG_RUNTIME_DIR at all, so I'm gonna go with it.
We want to store the Node REPL history in XDG_DATA_HOME, and we also
want to make sure we always have an npm config file that sets up npm
with its appropriate XDG paths. (By default, lots of stuff ends up in
~/.npm if no configuration is provided.)
As I mention in the diff, we can't simply commit the npm config file to
version control, because it contains things like authorisation tokens
that shouldn't be committed. We can however generate a default config
file that sets up the XDG paths we need, allowing the user to then go
ahead and add tokens to the generated file later on, like so.
An XDG runtime directory cannot be provided reliably by the shell,
because it's supposed to have the same lifetime as the user's login
session, and the shell doesn't have a reliable way to keep track of that
lifetime. There are probably nonportable ways to get a conforming
directory, such as making a request to PAM, but PAM is supposed to set
XDG_RUNTIME_DIR itself anyway and also doesn't exist on Macs, which I
use most of the time.
My configuration isn't actually using XDG_RUNTIME_DIR anyway, so I don't
want to provide the misleading impression that a runtime directory with
proper behaviour conforming to the specification is definitely
available.