Skip to content

Commit e1b957d

Browse files
committed
Require Node.js 12 and move to ESM
1 parent a9421d8 commit e1b957d

File tree

8 files changed

+169
-168
lines changed

8 files changed

+169
-168
lines changed

.github/workflows/main.yml

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ jobs:
1212
node-version:
1313
- 14
1414
- 12
15-
- 10
16-
- 8
1715
steps:
1816
- uses: actions/checkout@v2
1917
- uses: actions/setup-node@v1

index.d.ts

+77-81
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,77 @@
1-
declare const xdgBasedir: {
2-
/**
3-
Directory for user-specific data files.
4-
5-
@example
6-
```js
7-
import xdgBasedir = require('xdg-basedir');
8-
9-
xdgBasedir.data;
10-
//=> '/home/sindresorhus/.local/share'
11-
```
12-
*/
13-
readonly data?: string;
14-
15-
/**
16-
Directory for user-specific configuration files.
17-
18-
@example
19-
```js
20-
import xdgBasedir = require('xdg-basedir');
21-
22-
xdgBasedir.config;
23-
//=> '/home/sindresorhus/.config'
24-
```
25-
*/
26-
readonly config?: string;
27-
28-
/**
29-
Directory for user-specific non-essential data files.
30-
31-
@example
32-
```js
33-
import xdgBasedir = require('xdg-basedir');
34-
35-
xdgBasedir.cache;
36-
//=> '/home/sindresorhus/.cache'
37-
```
38-
*/
39-
readonly cache?: string;
40-
41-
/**
42-
Directory for user-specific non-essential runtime files and other file objects (such as sockets, named pipes, etc).
43-
44-
@example
45-
```js
46-
import xdgBasedir = require('xdg-basedir');
47-
48-
xdgBasedir.runtime;
49-
//=> '/run/user/sindresorhus'
50-
```
51-
*/
52-
readonly runtime?: string;
53-
54-
/**
55-
Preference-ordered array of base directories to search for data files in addition to `.data`.
56-
57-
@example
58-
```js
59-
import xdgBasedir = require('xdg-basedir');
60-
61-
xdgBasedir.dataDirs
62-
//=> ['/home/sindresorhus/.local/share', '/usr/local/share/', '/usr/share/']
63-
```
64-
*/
65-
readonly dataDirs: readonly string[];
66-
67-
/**
68-
Preference-ordered array of base directories to search for configuration files in addition to `.config`.
69-
70-
@example
71-
```js
72-
import xdgBasedir = require('xdg-basedir');
73-
74-
xdgBasedir.configDirs;
75-
//=> ['/home/sindresorhus/.config', '/etc/xdg']
76-
```
77-
*/
78-
readonly configDirs: readonly string[];
79-
};
80-
81-
export = xdgBasedir;
1+
/**
2+
Directory for user-specific data files.
3+
4+
@example
5+
```
6+
import {xdgData} from 'xdg-basedir';
7+
8+
console.log(xdgData);
9+
//=> '/home/sindresorhus/.local/share'
10+
```
11+
*/
12+
export const xdgData: string | undefined;
13+
14+
/**
15+
Directory for user-specific configuration files.
16+
17+
@example
18+
```
19+
import {xdgConfig} from 'xdg-basedir';
20+
21+
console.log(xdgConfig);
22+
//=> '/home/sindresorhus/.config'
23+
```
24+
*/
25+
export const xdgConfig: string | undefined;
26+
27+
/**
28+
Directory for user-specific non-essential data files.
29+
30+
@example
31+
```
32+
import {xdgCache} from 'xdg-basedir';
33+
34+
console.log(xdgCache);
35+
//=> '/home/sindresorhus/.cache'
36+
```
37+
*/
38+
export const xdgCache: string | undefined;
39+
40+
/**
41+
Directory for user-specific non-essential runtime files and other file objects (such as sockets, named pipes, etc).
42+
43+
@example
44+
```
45+
import {xdgRuntime} from 'xdg-basedir';
46+
47+
console.log(xdgRuntime);
48+
//=> '/run/user/sindresorhus'
49+
```
50+
*/
51+
export const xdgRuntime: string | undefined;
52+
53+
/**
54+
Preference-ordered array of base directories to search for data files in addition to `xdgData`.
55+
56+
@example
57+
```
58+
import {xdgDataDirectories} from 'xdg-basedir';
59+
60+
console.log(xdgDataDirectories);
61+
//=> ['/home/sindresorhus/.local/share', '/usr/local/share/', '/usr/share/']
62+
```
63+
*/
64+
export const xdgDataDirectories: readonly string[];
65+
66+
/**
67+
Preference-ordered array of base directories to search for configuration files in addition to `xdgConfig`.
68+
69+
@example
70+
```
71+
import {xdgConfigDirectories} from 'xdg-basedir';
72+
73+
console.log(xdgConfigDirectories);
74+
//=> ['/home/sindresorhus/.config', '/etc/xdg']
75+
```
76+
*/
77+
export const xdgConfigDirectories: readonly string[];

index.js

+12-13
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
1-
'use strict';
2-
const os = require('os');
3-
const path = require('path');
1+
import os from 'os';
2+
import path from 'path';
43

54
const homeDirectory = os.homedir();
65
const {env} = process;
76

8-
exports.data = env.XDG_DATA_HOME ||
7+
export const data = env.XDG_DATA_HOME ||
98
(homeDirectory ? path.join(homeDirectory, '.local', 'share') : undefined);
109

11-
exports.config = env.XDG_CONFIG_HOME ||
10+
export const config = env.XDG_CONFIG_HOME ||
1211
(homeDirectory ? path.join(homeDirectory, '.config') : undefined);
1312

14-
exports.cache = env.XDG_CACHE_HOME || (homeDirectory ? path.join(homeDirectory, '.cache') : undefined);
13+
export const cache = env.XDG_CACHE_HOME || (homeDirectory ? path.join(homeDirectory, '.cache') : undefined);
1514

16-
exports.runtime = env.XDG_RUNTIME_DIR || undefined;
15+
export const runtime = env.XDG_RUNTIME_DIR || undefined;
1716

18-
exports.dataDirs = (env.XDG_DATA_DIRS || '/usr/local/share/:/usr/share/').split(':');
17+
export const dataDirs = (env.XDG_DATA_DIRS || '/usr/local/share/:/usr/share/').split(':');
1918

20-
if (exports.data) {
21-
exports.dataDirs.unshift(exports.data);
19+
if (data) {
20+
dataDirs.unshift(data);
2221
}
2322

24-
exports.configDirs = (env.XDG_CONFIG_DIRS || '/etc/xdg').split(':');
23+
export const configDirs = (env.XDG_CONFIG_DIRS || '/etc/xdg').split(':');
2524

26-
if (exports.config) {
27-
exports.configDirs.unshift(exports.config);
25+
if (config) {
26+
configDirs.unshift(config);
2827
}

index.test-d.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import {expectType, expectError} from 'tsd';
2-
import xdgBasedir = require('.');
2+
import {xdgData, xdgConfig, xdgCache, xdgRuntime, xdgConfigDirectories, xdgDataDirectories} from './index.js';
33

4-
expectType<string | undefined>(xdgBasedir.data);
5-
expectError<string>(xdgBasedir.data);
6-
expectType<string | undefined>(xdgBasedir.config);
7-
expectError<string>(xdgBasedir.config);
8-
expectType<string | undefined>(xdgBasedir.cache);
9-
expectError<string>(xdgBasedir.cache);
10-
expectType<string | undefined>(xdgBasedir.runtime);
11-
expectError<string>(xdgBasedir.runtime);
12-
expectType<readonly string[]>(xdgBasedir.configDirs);
13-
expectError<string[]>(xdgBasedir.configDirs);
14-
expectType<readonly string[]>(xdgBasedir.dataDirs);
15-
expectError<string[]>(xdgBasedir.dataDirs);
4+
expectType<string | undefined>(xdgData);
5+
expectError<string>(xdgData);
6+
expectType<string | undefined>(xdgCache);
7+
expectError<string>(xdgCache);
8+
expectType<string | undefined>(xdgCache);
9+
expectError<string>(xdgCache);
10+
expectType<string | undefined>(xdgRuntime);
11+
expectError<string>(xdgRuntime);
12+
expectType<readonly string[]>(xdgConfigDirectories);
13+
expectError<string[]>(xdgConfigDirectories);
14+
expectType<readonly string[]>(xdgDataDirectories);
15+
expectError<string[]>(xdgDataDirectories);

license

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) Sindre Sorhus <[email protected]> (sindresorhus.com)
3+
Copyright (c) Sindre Sorhus <[email protected]> (https://sindresorhus.com)
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
66

package.json

+8-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
"description": "Get XDG Base Directory paths",
55
"license": "MIT",
66
"repository": "sindresorhus/xdg-basedir",
7+
"funding": "https://github.com/sponsors/sindresorhus",
78
"author": {
89
"name": "Sindre Sorhus",
910
"email": "[email protected]",
10-
"url": "sindresorhus.com"
11+
"url": "https://sindresorhus.com"
1112
},
13+
"type": "module",
14+
"exports": "./index.js",
1215
"engines": {
13-
"node": ">=8"
16+
"node": ">=12"
1417
},
1518
"scripts": {
1619
"test": "xo && ava && tsd"
@@ -37,5 +40,8 @@
3740
"import-fresh": "^3.0.0",
3841
"tsd": "^0.7.2",
3942
"xo": "^0.24.0"
43+
},
44+
"ava": {
45+
"serial": true
4046
}
4147
}

readme.md

+14-18
Original file line numberDiff line numberDiff line change
@@ -2,60 +2,56 @@
22

33
> Get [XDG Base Directory](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html) paths
44
5-
This package is meant for Linux. You should not use XDG on macOS and Windows. Instead, you should follow their platform conventions. You can use [`env-paths`](https://github.com/sindresorhus/env-paths) for that.
6-
5+
This package is meant for Linux. You should not use XDG on macOS or Windows. Instead, you should follow their platform conventions. You can use [`env-paths`](https://github.com/sindresorhus/env-paths) for that.
76

87
## Install
98

109
```
1110
$ npm install xdg-basedir
1211
```
1312

14-
1513
## Usage
1614

1715
```js
18-
const xdgBasedir = require('xdg-basedir');
16+
import {xdgData, xdgConfig, xdgDataDirectories} from 'xdg-basedir';
1917

20-
xdgBasedir.data;
18+
console.log(xdgData);
2119
//=> '/home/sindresorhus/.local/share'
2220

23-
xdgBasedir.config;
21+
console.log(xdgConfig);
2422
//=> '/home/sindresorhus/.config'
2523

26-
xdgBasedir.dataDirs
24+
console.log(xdgDataDirectories);
2725
//=> ['/home/sindresorhus/.local/share', '/usr/local/share/', '/usr/share/']
2826
```
2927

30-
3128
## API
3229

33-
The properties `.data`, `.config`, `.cache`, `.runtime` will return `null` in the uncommon case that both the XDG environment variable is not set and the users home directory can't be found. You need to handle this case. A common solution is to [fall back to a temp directory](https://github.com/yeoman/configstore/blob/b82690fc401318ad18dcd7d151a0003a4898a314/index.js#L15).
30+
The exports `xdgData`, `xdgConfig`, `xdgCache`, `xdgRuntime` will return `undefined` in the uncommon case that both the XDG environment variable is not set and the users home directory can't be found. You need to handle this case. A common solution is to [fall back to a temporary directory](https://github.com/yeoman/configstore/blob/b82690fc401318ad18dcd7d151a0003a4898a314/index.js#L15).
3431

35-
### .data
32+
### xdgData
3633

3734
Directory for user-specific data files.
3835

39-
### .config
36+
### xdgConfig
4037

4138
Directory for user-specific configuration files.
4239

43-
### .cache
40+
### xdgCache
4441

4542
Directory for user-specific non-essential data files.
4643

47-
### .runtime
44+
### xdgRuntime
4845

4946
Directory for user-specific non-essential runtime files and other file objects (such as sockets, named pipes, etc).
5047

51-
### .dataDirs
52-
53-
Preference-ordered array of base directories to search for data files in addition to `.data`.
48+
### xdgDataDirectories
5449

55-
### .configDirs
50+
Preference-ordered array of base directories to search for data files in addition to `xdgData`.
5651

57-
Preference-ordered array of base directories to search for configuration files in addition to `.config`.
52+
### xdgConfigDirectories
5853

54+
Preference-ordered array of base directories to search for configuration files in addition to `xdgConfig`.
5955

6056
---
6157

0 commit comments

Comments
 (0)