dthree / vorpal

Node's framework for interactive CLIs
http://vorpal.js.org
MIT License
5.64k stars 280 forks source link

[for discussion] move default localStorage location under $HOME #122

Open mvayngrib opened 8 years ago

mvayngrib commented 8 years ago

i ran into a problem when trying out your cash project. With my nodejs/npm setup, global installs require sudo: sudo npm i -g cash

however, because of that, cash doesn't have permissions to write to its own localstorage directory:

$ cash
fs.js:794
  return binding.mkdir(pathModule._makeLong(path),
                 ^

Error: EACCES: permission denied, mkdir '/Users/tenaciousmv/npm/lib/node_modules/cash/node_modules/vorpal/dist/.local_storage'

obviously i don't want to run cash with sudo :)

isn't it more typical to put this kind of storage in ~/.vorpal or ~/.cash or somewhere else under $HOME?

GranularDetective commented 8 years ago

It depends what you're trying to achieve? If you're trying to input a long path into a short directory then you're going to see an error, if you'll forgive my use of non-standard coding jargon regarding this particular instance which is actually the best way to describe it at the moment.

mvayngrib commented 8 years ago

@GranularDetective not sure what you mean...i'm just talking about access privileges

Shakyamuni177te commented 8 years ago

Oh. Why do you want to sudo again? I suppose true root is much more enjoyable but in an actual coding sense what do you mean exactly?

On 1 March 2016 at 10:58, Mark Vayngrib notifications@github.com wrote:

@GranularDetective https://github.com/GranularDetective not sure what you mean...i'm just talking about access privileges

— Reply to this email directly or view it on GitHub https://github.com/dthree/vorpal/issues/122#issuecomment-190665160.

Shakyamuni177te commented 8 years ago

Why don't you want to sudo again, rather. Muh bad.

On 1 March 2016 at 11:10, Peter Carter peter.carter.mail@gmail.com wrote:

Oh. Why do you want to sudo again? I suppose true root is much more enjoyable but in an actual coding sense what do you mean exactly?

On 1 March 2016 at 10:58, Mark Vayngrib notifications@github.com wrote:

@GranularDetective https://github.com/GranularDetective not sure what you mean...i'm just talking about access privileges

— Reply to this email directly or view it on GitHub https://github.com/dthree/vorpal/issues/122#issuecomment-190665160.

dthree commented 8 years ago

@mvayngrib agreed. We just need a cross-platform temp dir. I think I implemented this in wat anyways, before I added localstorage to Vorpal.

Should be a pretty easy fix.

mvayngrib commented 8 years ago

@dthree if you don't end up separating it out of wat, there's user-home and home-or-tmp

Shakyamuni177te commented 8 years ago

You added local storage to Vorpal? To wat purpose? On 1 Mar 2016 17:16, "dc" notifications@github.com wrote:

@mvayngrib https://github.com/mvayngrib agreed. We just need a cross-platform temp dir. I think I implemented this in wat https://github.com/dthree/wat anyways, before I added localstorage to Vorpal.

Should be a pretty easy fix.

— Reply to this email directly or view it on GitHub https://github.com/dthree/vorpal/issues/122#issuecomment-190818855.

dthree commented 8 years ago

Okay thanks.

dthree commented 8 years ago

os.tmpdir() works fine.

Fixed in v1.10.7.

goodevilgenius commented 7 years ago

I know this is an old issue, but I just found it, while trying to figure out where this was stored.

I think using os.tmpdir() isn't a good idea, as, on some OSs (like Linux), this may default to a volatile directory. These files may not persist after a reboot.

I think the original suggestion of it being somewhere in the home directory is better. There's frequently a .cache directory in $HOME. That's where, e.g., yarn stores its module cache.

goodevilgenius commented 7 years ago

For reference, this is how yarn does it:

function getDirectory(category: string): string {
  // use %LOCALAPPDATA%/Yarn on Windows
  if (process.platform === 'win32' && process.env.LOCALAPPDATA) {
    return path.join(process.env.LOCALAPPDATA, 'Yarn', category);
  }

  // otherwise use ~/.{category}/yarn
  return path.join(userHome, `.${category}`, 'yarn');
}

function getCacheDirectory(): string {
  if (process.platform === 'darwin') {
    return path.join(userHome, 'Library', 'Caches', 'Yarn');
  }

  return getDirectory('cache');
}

So, getCacheDirectory() returns $HOME/.cache/yarn on Linux, %LOCALAPPDATA%\Yarn\cache on Windows, and $HOME/Libarary/Caches/Yarn on macOS.

I think something like that would be a good option for vorpal.