Skip to content

Commit 96179ad

Browse files
authored
feat: add .haf extension by default (#30)
1 parent fe8f535 commit 96179ad

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

spec/get-store-path.spec.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ const describeIfUnix = isWindows ? describe.skip : describe;
1010

1111
const splitKey = isWindows ? '\\' : '/';
1212

13-
describe('get-config-path', () => {
13+
describe('get-store-path', () => {
1414
describe('extension', () => {
1515
describe('when absent', () => {
16-
it('should skip extension', () => {
16+
it('should add .haf extension', () => {
1717
const path = getStorePath('pop');
1818

19-
const index = path.split(splitKey).lastIndexOf('pop');
19+
const index = path.split(splitKey).lastIndexOf('pop.haf');
2020

2121
expect(index).toBeGreaterThanOrEqual(0);
2222
});
@@ -47,7 +47,7 @@ describe('get-config-path', () => {
4747
it('should respect CONFIG_DIR', () => {
4848
const path = getStorePath('pop');
4949

50-
expect(path).toEqual('/home/config_dir/pop');
50+
expect(path).toEqual('/home/config_dir/pop.haf');
5151
});
5252
});
5353

@@ -63,15 +63,15 @@ describe('get-config-path', () => {
6363
it('should respect XDG_CONFIG_HOME', () => {
6464
const path = getStorePath('pop');
6565

66-
expect(path).toEqual('/home/xdg_config_home/pop');
66+
expect(path).toEqual('/home/xdg_config_home/pop.haf');
6767
});
6868
});
6969

7070
describe('when fallback', () => {
7171
const spy = jest.spyOn(os, 'homedir');
7272

7373
beforeEach(() => {
74-
spy.mockReturnValue('/Users/anda');
74+
spy.mockReturnValue('/Users/pop');
7575
});
7676

7777
afterEach(() => {
@@ -81,7 +81,7 @@ describe('get-config-path', () => {
8181
it('should put under ~/.config', () => {
8282
const path = getStorePath('pop');
8383

84-
expect(path).toEqual('/Users/anda/.config/pop');
84+
expect(path).toEqual('/Users/pop/.config/pop.haf');
8585
});
8686
});
8787
});
@@ -98,7 +98,7 @@ describe('get-config-path', () => {
9898
it('should deal with WINDOWS', () => {
9999
const path = getStorePath('pop');
100100

101-
expect(path).toEqual('C:\\Users\\Pop\\ApplicationData\\pop');
101+
expect(path).toEqual('C:\\Users\\Pop\\ApplicationData\\pop.haf');
102102
});
103103
});
104104
});

src/get-store-path.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
import path from 'path';
22
import os from 'os';
33

4-
export const getStorePath = (name: string, extension?: string): string => {
5-
if (extension) {
6-
name += `.${extension}`;
7-
}
4+
export const getStorePath = (name: string, extension = 'haf'): string => {
5+
const fileName = `${name}.${extension}`;
86

9-
const confDir =
7+
const storeDir =
108
process.env['CONFIG_DIR'] ||
119
process.env['XDG_CONFIG_HOME'] ||
1210
(os.platform() === 'win32' && process.env['LOCALAPPDATA']) ||
1311
path.join(os.homedir(), '.config');
1412

15-
return path.join(confDir, name);
13+
return path.join(storeDir, fileName);
1614
};

0 commit comments

Comments
 (0)