Skip to content

Commit

Permalink
fix: use proper default value for store-dir, cache-dir on macOS
Browse files Browse the repository at this point in the history
ref #2574
  • Loading branch information
zkochan committed Jul 7, 2021
1 parent 489ee02 commit 2264bfd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/plenty-moose-tie.md
@@ -0,0 +1,5 @@
---
"@pnpm/config": patch
---

Choose proper default state-dir and cache-dir on macOS.
5 changes: 4 additions & 1 deletion packages/config/src/dirs.ts
Expand Up @@ -10,6 +10,9 @@ export function getCacheDir (
if (opts.env.XDG_CACHE_HOME) {
return path.join(opts.env.XDG_CACHE_HOME, 'pnpm')
}
if (opts.platform === 'darwin') {
return path.join(os.homedir(), 'Library/Caches/pnpm')
}
if (opts.platform !== 'win32') {
return path.join(os.homedir(), '.cache/pnpm')
}
Expand All @@ -28,7 +31,7 @@ export function getStateDir (
if (opts.env.XDG_STATE_HOME) {
return path.join(opts.env.XDG_STATE_HOME, 'pnpm')
}
if (opts.platform !== 'win32') {
if (opts.platform !== 'win32' && opts.platform !== 'darwin') {
return path.join(os.homedir(), '.local/state/pnpm')
}
if (opts.env.LOCALAPPDATA) {
Expand Down
8 changes: 8 additions & 0 deletions packages/config/test/dirs.test.ts
Expand Up @@ -13,6 +13,10 @@ test('getCacheDir()', () => {
env: {},
platform: 'linux',
})).toBe(path.join(os.homedir(), '.cache/pnpm'))
expect(getCacheDir({
env: {},
platform: 'darwin',
})).toBe(path.join(os.homedir(), 'Library/Caches/pnpm'))
expect(getCacheDir({
env: {
LOCALAPPDATA: '/localappdata',
Expand All @@ -36,6 +40,10 @@ test('getStateDir()', () => {
env: {},
platform: 'linux',
})).toBe(path.join(os.homedir(), '.local/state/pnpm'))
expect(getStateDir({
env: {},
platform: 'darwin',
})).toBe(path.join(os.homedir(), '.pnpm-state'))
expect(getStateDir({
env: {
LOCALAPPDATA: '/localappdata',
Expand Down

0 comments on commit 2264bfd

Please sign in to comment.