os-user-dirs 2.4.0 → 2.5.0
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.
- package/README.md +24 -0
- package/index.d.ts +18 -0
- package/index.js +55 -0
- package/index.mjs +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -66,6 +66,22 @@ getBasePath("config");
|
|
|
66
66
|
//=> '/home/user/.config'
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
+
#### System search directories
|
|
70
|
+
|
|
71
|
+
```javascript
|
|
72
|
+
import { configDirs, dataDirs } from "os-user-dirs";
|
|
73
|
+
|
|
74
|
+
configDirs();
|
|
75
|
+
//=> ['/etc/xdg'] (Linux)
|
|
76
|
+
//=> ['/Library/Application Support', '/Library/Preferences'] (macOS)
|
|
77
|
+
//=> ['C:\\ProgramData'] (Windows)
|
|
78
|
+
|
|
79
|
+
dataDirs();
|
|
80
|
+
//=> ['/usr/local/share', '/usr/share'] (Linux)
|
|
81
|
+
//=> ['/Library/Application Support'] (macOS)
|
|
82
|
+
//=> ['C:\\ProgramData'] (Windows)
|
|
83
|
+
```
|
|
84
|
+
|
|
69
85
|
#### Project directories
|
|
70
86
|
|
|
71
87
|
```javascript
|
|
@@ -172,6 +188,14 @@ Returns the path to the runtime directory (`$XDG_RUNTIME_DIR` on Linux), or `nul
|
|
|
172
188
|
#### `getBasePath(name)`
|
|
173
189
|
Returns the path to the specified base directory. Valid names: `config`, `data`, `cache`, `state`, `log`, `runtime`.
|
|
174
190
|
|
|
191
|
+
### System Search Directories
|
|
192
|
+
|
|
193
|
+
#### `configDirs()`
|
|
194
|
+
Returns the system config directory search path list (`string[]`). On Linux, reads `$XDG_CONFIG_DIRS` (default: `["/etc/xdg"]`). On macOS: `["/Library/Application Support", "/Library/Preferences"]`. On Windows: `[%PROGRAMDATA%]`.
|
|
195
|
+
|
|
196
|
+
#### `dataDirs()`
|
|
197
|
+
Returns the system data directory search path list (`string[]`). On Linux, reads `$XDG_DATA_DIRS` (default: `["/usr/local/share", "/usr/share"]`). On macOS: `["/Library/Application Support"]`. On Windows: `[%PROGRAMDATA%]`.
|
|
198
|
+
|
|
175
199
|
### Project Directories
|
|
176
200
|
|
|
177
201
|
#### `projectDirs(name, options?)`
|
package/index.d.ts
CHANGED
|
@@ -47,6 +47,22 @@ export function logDir(): string;
|
|
|
47
47
|
/** Returns the path to the XDG runtime directory, or null if unavailable. */
|
|
48
48
|
export function runtimeDir(): string | null;
|
|
49
49
|
|
|
50
|
+
/**
|
|
51
|
+
* Returns the system config directory search path list.
|
|
52
|
+
* On Linux, reads `$XDG_CONFIG_DIRS` (default: `["/etc/xdg"]`).
|
|
53
|
+
* On macOS: `["/Library/Application Support", "/Library/Preferences"]`.
|
|
54
|
+
* On Windows: `[%PROGRAMDATA%]`.
|
|
55
|
+
*/
|
|
56
|
+
export function configDirs(): string[];
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Returns the system data directory search path list.
|
|
60
|
+
* On Linux, reads `$XDG_DATA_DIRS` (default: `["/usr/local/share", "/usr/share"]`).
|
|
61
|
+
* On macOS: `["/Library/Application Support"]`.
|
|
62
|
+
* On Windows: `[%PROGRAMDATA%]`.
|
|
63
|
+
*/
|
|
64
|
+
export function dataDirs(): string[];
|
|
65
|
+
|
|
50
66
|
/** Returns the path to the specified base directory. */
|
|
51
67
|
export function getBasePath(name: "config"): string;
|
|
52
68
|
export function getBasePath(name: "data"): string;
|
|
@@ -108,6 +124,8 @@ declare const osUserDirs: typeof downloads & {
|
|
|
108
124
|
logDir: typeof logDir;
|
|
109
125
|
runtimeDir: typeof runtimeDir;
|
|
110
126
|
getBasePath: typeof getBasePath;
|
|
127
|
+
configDirs: typeof configDirs;
|
|
128
|
+
dataDirs: typeof dataDirs;
|
|
111
129
|
projectDirs: typeof projectDirs;
|
|
112
130
|
getXDGUserDir: typeof getXDGUserDir;
|
|
113
131
|
getXDGDownloadDir: typeof getXDGDownloadDir;
|
package/index.js
CHANGED
|
@@ -144,6 +144,59 @@ function stateDir() { return resolveBase("state"); }
|
|
|
144
144
|
function logDir() { return resolveBase("log"); }
|
|
145
145
|
function runtimeDir() { return resolveBase("runtime"); }
|
|
146
146
|
|
|
147
|
+
const SEARCH_DIRS_CONFIG = {
|
|
148
|
+
config: {
|
|
149
|
+
env: "XDG_CONFIG_DIRS",
|
|
150
|
+
linux: ["/etc/xdg"],
|
|
151
|
+
darwin: ["/Library/Application Support", "/Library/Preferences"],
|
|
152
|
+
win32: "PROGRAMDATA",
|
|
153
|
+
},
|
|
154
|
+
data: {
|
|
155
|
+
env: "XDG_DATA_DIRS",
|
|
156
|
+
linux: ["/usr/local/share", "/usr/share"],
|
|
157
|
+
darwin: ["/Library/Application Support"],
|
|
158
|
+
win32: "PROGRAMDATA",
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
function resolveSearchDirs(name) {
|
|
163
|
+
const cfg = SEARCH_DIRS_CONFIG[name];
|
|
164
|
+
if (!cfg) {
|
|
165
|
+
throw new Error("Unknown search directory: " + name + ". Valid names: " + Object.keys(SEARCH_DIRS_CONFIG).join(", "));
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const platform = process.platform;
|
|
169
|
+
|
|
170
|
+
if (platform === "linux") {
|
|
171
|
+
const envVal = process.env[cfg.env];
|
|
172
|
+
if (envVal) {
|
|
173
|
+
const dirs = envVal.split(":").filter(Boolean);
|
|
174
|
+
if (dirs.length > 0) {
|
|
175
|
+
return dirs.map(function (d) { return path.resolve(d); });
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return cfg.linux.slice();
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (platform === "darwin") {
|
|
182
|
+
return cfg.darwin.slice();
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (platform === "win32") {
|
|
186
|
+
const winVal = process.env[cfg.win32];
|
|
187
|
+
if (winVal) {
|
|
188
|
+
return [path.resolve(winVal)];
|
|
189
|
+
}
|
|
190
|
+
return [path.join(process.env.SYSTEMDRIVE || "C:", "ProgramData")];
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Unknown platform: use Linux defaults
|
|
194
|
+
return cfg.linux.slice();
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function configDirs() { return resolveSearchDirs("config"); }
|
|
198
|
+
function dataDirs() { return resolveSearchDirs("data"); }
|
|
199
|
+
|
|
147
200
|
function getBasePath(name) {
|
|
148
201
|
return resolveBase(name);
|
|
149
202
|
}
|
|
@@ -226,6 +279,8 @@ module.exports.stateDir = stateDir;
|
|
|
226
279
|
module.exports.logDir = logDir;
|
|
227
280
|
module.exports.runtimeDir = runtimeDir;
|
|
228
281
|
module.exports.getBasePath = getBasePath;
|
|
282
|
+
module.exports.configDirs = configDirs;
|
|
283
|
+
module.exports.dataDirs = dataDirs;
|
|
229
284
|
module.exports.projectDirs = projectDirs;
|
|
230
285
|
module.exports.getXDGUserDir = getXDGUserDir;
|
|
231
286
|
|
package/index.mjs
CHANGED
|
@@ -17,6 +17,8 @@ export const stateDir = osUserDirs.stateDir;
|
|
|
17
17
|
export const logDir = osUserDirs.logDir;
|
|
18
18
|
export const runtimeDir = osUserDirs.runtimeDir;
|
|
19
19
|
export const getBasePath = osUserDirs.getBasePath;
|
|
20
|
+
export const configDirs = osUserDirs.configDirs;
|
|
21
|
+
export const dataDirs = osUserDirs.dataDirs;
|
|
20
22
|
export const projectDirs = osUserDirs.projectDirs;
|
|
21
23
|
export const getXDGUserDir = osUserDirs.getXDGUserDir;
|
|
22
24
|
export const getXDGDownloadDir = osUserDirs.getXDGDownloadDir;
|
package/package.json
CHANGED