@vltpkg/xdg 1.0.0-rc.23 → 1.0.0-rc.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,13 @@
1
+ export type PathType = 'cache' | 'config' | 'data' | 'runtime' | 'state';
2
+ export declare class XDG {
3
+ name: string;
4
+ base: {
5
+ [k in PathType]: string;
6
+ };
7
+ constructor(name: string);
8
+ config(p?: string): string;
9
+ cache(p?: string): string;
10
+ data(p?: string): string;
11
+ state(p?: string): string;
12
+ runtime(p?: string): string;
13
+ }
package/dist/index.js ADDED
@@ -0,0 +1,83 @@
1
+ import { homedir, tmpdir } from 'node:os';
2
+ import { resolve } from 'node:path';
3
+ const root = homedir();
4
+ const path = (p) => resolve(root, p);
5
+ const defaults = process.platform === 'darwin' ?
6
+ (which) => {
7
+ switch (which) {
8
+ case 'config':
9
+ return path('Library/Preferences');
10
+ case 'cache':
11
+ return path('Library/Caches');
12
+ case 'data':
13
+ return path('Library/Application Support');
14
+ case 'state':
15
+ return path('Library/State');
16
+ case 'runtime':
17
+ return resolve(tmpdir(),
18
+ /* c8 ignore next */
19
+ String(process.getuid?.() ?? ''), '.run');
20
+ }
21
+ }
22
+ : process.platform === 'win32' ?
23
+ (which) => {
24
+ const ad = process.env.APPDATA ?? path('AppData/Roaming');
25
+ const lad = process.env.LOCALAPPDATA ?? path('AppData/Local');
26
+ switch (which) {
27
+ case 'config':
28
+ return resolve(ad, 'xdg.config');
29
+ case 'cache':
30
+ return resolve(lad, 'xdg.cache');
31
+ case 'data':
32
+ return resolve(ad, 'xdg.data');
33
+ case 'state':
34
+ return resolve(lad, 'xdg.state');
35
+ case 'runtime':
36
+ return resolve(tmpdir(), 'xdg.run');
37
+ }
38
+ }
39
+ : (which) => {
40
+ switch (which) {
41
+ case 'config':
42
+ return path('.config');
43
+ case 'cache':
44
+ return path('.cache');
45
+ case 'data':
46
+ return path('.local/share');
47
+ case 'state':
48
+ return path('.local/state');
49
+ case 'runtime':
50
+ return resolve(tmpdir(),
51
+ /* c8 ignore next */
52
+ String(process.getuid?.() ?? ''), '.run');
53
+ }
54
+ };
55
+ const { XDG_CONFIG_HOME = defaults('config'), XDG_CACHE_HOME = defaults('cache'), XDG_DATA_HOME = defaults('data'), XDG_STATE_HOME = defaults('state'), XDG_RUNTIME_DIR = defaults('runtime'), } = process.env;
56
+ export class XDG {
57
+ name;
58
+ base = {
59
+ config: XDG_CONFIG_HOME,
60
+ cache: XDG_CACHE_HOME,
61
+ data: XDG_DATA_HOME,
62
+ state: XDG_STATE_HOME,
63
+ runtime: XDG_RUNTIME_DIR,
64
+ };
65
+ constructor(name) {
66
+ this.name = name;
67
+ }
68
+ config(p = '') {
69
+ return resolve(this.base.config, this.name, p);
70
+ }
71
+ cache(p = '') {
72
+ return resolve(this.base.cache, this.name, p);
73
+ }
74
+ data(p = '') {
75
+ return resolve(this.base.data, this.name, p);
76
+ }
77
+ state(p = '') {
78
+ return resolve(this.base.state, this.name, p);
79
+ }
80
+ runtime(p = '') {
81
+ return resolve(this.base.runtime, this.name, p);
82
+ }
83
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vltpkg/xdg",
3
3
  "description": "platform-specific app directories following XDG spec",
4
- "version": "1.0.0-rc.23",
4
+ "version": "1.0.0-rc.25",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/vltpkg/vltpkg.git",