Skip to content

Commit 995e663

Browse files
committed
Require Node.js 12.20 and move to ESM
1 parent 62d4ec8 commit 995e663

File tree

8 files changed

+100
-120
lines changed

8 files changed

+100
-120
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,10 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
node-version:
13-
- 14
14-
- 12
15-
- 10
16-
- 8
13+
- 16
1714
steps:
1815
- uses: actions/checkout@v2
19-
- uses: actions/setup-node@v1
16+
- uses: actions/setup-node@v2
2017
with:
2118
node-version: ${{ matrix.node-version }}
2219
- run: npm install

index.d.ts

Lines changed: 65 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,90 @@
1-
declare namespace envPaths {
2-
export interface Options {
3-
/**
4-
__Don't use this option unless you really have to!__
1+
export interface Options {
2+
/**
3+
__Don't use this option unless you really have to!__
54
6-
Suffix appended to the project name to avoid name conflicts with native apps. Pass an empty string to disable it.
5+
Suffix appended to the project name to avoid name conflicts with native apps. Pass an empty string to disable it.
76
8-
@default 'nodejs'
9-
*/
10-
readonly suffix?: string;
11-
}
7+
@default 'nodejs'
8+
*/
9+
readonly suffix?: string;
10+
}
1211

13-
export interface Paths {
14-
/**
15-
Directory for data files.
12+
export interface Paths {
13+
/**
14+
Directory for data files.
1615
17-
Example locations (with the default `nodejs` suffix):
16+
Example locations (with the default `nodejs` suffix):
1817
19-
- macOS: `~/Library/Application Support/MyApp-nodejs`
20-
- Windows: `%LOCALAPPDATA%\MyApp-nodejs\Data` (for example, `C:\Users\USERNAME\AppData\Local\MyApp-nodejs\Data`)
21-
- Linux: `~/.local/share/MyApp-nodejs` (or `$XDG_DATA_HOME/MyApp-nodejs`)
22-
*/
23-
readonly data: string;
18+
- macOS: `~/Library/Application Support/MyApp-nodejs`
19+
- Windows: `%LOCALAPPDATA%\MyApp-nodejs\Data` (for example, `C:\Users\USERNAME\AppData\Local\MyApp-nodejs\Data`)
20+
- Linux: `~/.local/share/MyApp-nodejs` (or `$XDG_DATA_HOME/MyApp-nodejs`)
21+
*/
22+
readonly data: string;
2423

25-
/**
26-
Directory for data files.
24+
/**
25+
Directory for data files.
2726
28-
Example locations (with the default `nodejs` suffix):
27+
Example locations (with the default `nodejs` suffix):
2928
30-
- macOS: `~/Library/Preferences/MyApp-nodejs`
31-
- Windows: `%APPDATA%\MyApp-nodejs\Config` (for example, `C:\Users\USERNAME\AppData\Roaming\MyApp-nodejs\Config`)
32-
- Linux: `~/.config/MyApp-nodejs` (or `$XDG_CONFIG_HOME/MyApp-nodejs`)
33-
*/
34-
readonly config: string;
29+
- macOS: `~/Library/Preferences/MyApp-nodejs`
30+
- Windows: `%APPDATA%\MyApp-nodejs\Config` (for example, `C:\Users\USERNAME\AppData\Roaming\MyApp-nodejs\Config`)
31+
- Linux: `~/.config/MyApp-nodejs` (or `$XDG_CONFIG_HOME/MyApp-nodejs`)
32+
*/
33+
readonly config: string;
3534

36-
/**
37-
Directory for non-essential data files.
35+
/**
36+
Directory for non-essential data files.
3837
39-
Example locations (with the default `nodejs` suffix):
38+
Example locations (with the default `nodejs` suffix):
4039
41-
- macOS: `~/Library/Caches/MyApp-nodejs`
42-
- Windows: `%LOCALAPPDATA%\MyApp-nodejs\Cache` (for example, `C:\Users\USERNAME\AppData\Local\MyApp-nodejs\Cache`)
43-
- Linux: `~/.cache/MyApp-nodejs` (or `$XDG_CACHE_HOME/MyApp-nodejs`)
44-
*/
45-
readonly cache: string;
40+
- macOS: `~/Library/Caches/MyApp-nodejs`
41+
- Windows: `%LOCALAPPDATA%\MyApp-nodejs\Cache` (for example, `C:\Users\USERNAME\AppData\Local\MyApp-nodejs\Cache`)
42+
- Linux: `~/.cache/MyApp-nodejs` (or `$XDG_CACHE_HOME/MyApp-nodejs`)
43+
*/
44+
readonly cache: string;
4645

47-
/**
48-
Directory for log files.
46+
/**
47+
Directory for log files.
4948
50-
Example locations (with the default `nodejs` suffix):
49+
Example locations (with the default `nodejs` suffix):
5150
52-
- macOS: `~/Library/Logs/MyApp-nodejs`
53-
- Windows: `%LOCALAPPDATA%\MyApp-nodejs\Log` (for example, `C:\Users\USERNAME\AppData\Local\MyApp-nodejs\Log`)
54-
- Linux: `~/.local/state/MyApp-nodejs` (or `$XDG_STATE_HOME/MyApp-nodejs`)
55-
*/
56-
readonly log: string;
51+
- macOS: `~/Library/Logs/MyApp-nodejs`
52+
- Windows: `%LOCALAPPDATA%\MyApp-nodejs\Log` (for example, `C:\Users\USERNAME\AppData\Local\MyApp-nodejs\Log`)
53+
- Linux: `~/.local/state/MyApp-nodejs` (or `$XDG_STATE_HOME/MyApp-nodejs`)
54+
*/
55+
readonly log: string;
5756

58-
/**
59-
Directory for temporary files.
57+
/**
58+
Directory for temporary files.
6059
61-
Example locations (with the default `nodejs` suffix):
60+
Example locations (with the default `nodejs` suffix):
6261
63-
- macOS: `/var/folders/jf/f2twvvvs5jl_m49tf034ffpw0000gn/T/MyApp-nodejs`
64-
- Windows: `%LOCALAPPDATA%\Temp\MyApp-nodejs` (for example, `C:\Users\USERNAME\AppData\Local\Temp\MyApp-nodejs`)
65-
- Linux: `/tmp/USERNAME/MyApp-nodejs`
66-
*/
67-
readonly temp: string;
68-
}
62+
- macOS: `/var/folders/jf/f2twvvvs5jl_m49tf034ffpw0000gn/T/MyApp-nodejs`
63+
- Windows: `%LOCALAPPDATA%\Temp\MyApp-nodejs` (for example, `C:\Users\USERNAME\AppData\Local\Temp\MyApp-nodejs`)
64+
- Linux: `/tmp/USERNAME/MyApp-nodejs`
65+
*/
66+
readonly temp: string;
6967
}
7068

71-
declare const envPaths: {
72-
/**
73-
Get paths for storing things like data, config, cache, etc.
74-
75-
Note: It only generates the path strings. It doesn't create the directories for you. You could use [`make-dir`](https://github.com/sindresorhus/make-dir) to create the directories.
69+
/**
70+
Get paths for storing things like data, config, cache, etc.
7671
77-
@param name - Name of your project. Used to generate the paths.
78-
@returns The paths to use for your project on current OS.
72+
Note: It only generates the path strings. It doesn't create the directories for you. You could use [`make-dir`](https://github.com/sindresorhus/make-dir) to create the directories.
7973
80-
@example
81-
```
82-
import envPaths = require('env-paths');
74+
@param name - The name of your project. Used to generate the paths.
75+
@returns The paths to use for your project on current OS.
8376
84-
const paths = envPaths('MyApp');
77+
@example
78+
```
79+
import envPaths from 'env-paths';
8580
86-
paths.data;
87-
//=> '/home/sindresorhus/.local/share/MyApp-nodejs'
88-
89-
paths.config
90-
//=> '/home/sindresorhus/.config/MyApp-nodejs'
91-
```
92-
*/
93-
(name: string, options?: envPaths.Options): envPaths.Paths;
81+
const paths = envPaths('MyApp');
9482
95-
// TODO: Remove this for the next major release, refactor the whole definition to:
96-
// declare function envPaths(name: string, options?: envPaths.Options): envPaths.Paths;
97-
// export = envPaths;
98-
default: typeof envPaths;
99-
};
83+
paths.data;
84+
//=> '/home/sindresorhus/.local/share/MyApp-nodejs'
10085
101-
export = envPaths;
86+
paths.config
87+
//=> '/home/sindresorhus/.config/MyApp-nodejs'
88+
```
89+
*/
90+
export default function envPaths(name: string, options?: Options): Paths;

index.js

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
'use strict';
2-
const path = require('path');
3-
const os = require('os');
1+
import path from 'node:path';
2+
import os from 'node:os';
3+
import process from 'node:process';
44

55
const homedir = os.homedir();
66
const tmpdir = os.tmpdir();
@@ -14,7 +14,7 @@ const macos = name => {
1414
config: path.join(library, 'Preferences', name),
1515
cache: path.join(library, 'Caches', name),
1616
log: path.join(library, 'Logs', name),
17-
temp: path.join(tmpdir, name)
17+
temp: path.join(tmpdir, name),
1818
};
1919
};
2020

@@ -28,7 +28,7 @@ const windows = name => {
2828
config: path.join(appData, name, 'Config'),
2929
cache: path.join(localAppData, name, 'Cache'),
3030
log: path.join(localAppData, name, 'Log'),
31-
temp: path.join(tmpdir, name)
31+
temp: path.join(tmpdir, name),
3232
};
3333
};
3434

@@ -42,20 +42,18 @@ const linux = name => {
4242
cache: path.join(env.XDG_CACHE_HOME || path.join(homedir, '.cache'), name),
4343
// https://wiki.debian.org/XDGBaseDirectorySpecification#state
4444
log: path.join(env.XDG_STATE_HOME || path.join(homedir, '.local', 'state'), name),
45-
temp: path.join(tmpdir, username, name)
45+
temp: path.join(tmpdir, username, name),
4646
};
4747
};
4848

49-
const envPaths = (name, options) => {
49+
export default function envPaths(name, {suffix = 'nodejs'} = {}) {
5050
if (typeof name !== 'string') {
51-
throw new TypeError(`Expected string, got ${typeof name}`);
51+
throw new TypeError(`Expected a string, got ${typeof name}`);
5252
}
5353

54-
options = Object.assign({suffix: 'nodejs'}, options);
55-
56-
if (options.suffix) {
54+
if (suffix) {
5755
// Add suffix to prevent possible conflict with native apps
58-
name += `-${options.suffix}`;
56+
name += `-${suffix}`;
5957
}
6058

6159
if (process.platform === 'darwin') {
@@ -67,8 +65,4 @@ const envPaths = (name, options) => {
6765
}
6866

6967
return linux(name);
70-
};
71-
72-
module.exports = envPaths;
73-
// TODO: Remove this for the next major release
74-
module.exports.default = envPaths;
68+
}

index.test-d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {expectType} from 'tsd';
2-
import envPaths = require('.');
3-
import {Paths} from '.';
2+
import envPaths, {Paths} from './index.js';
43

54
expectType<Paths>(envPaths('MyApp'));
65
expectType<Paths>(envPaths('MyApp', {suffix: 'test'}));

license

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
3+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
"description": "Get paths for storing things like data, config, cache, etc",
55
"license": "MIT",
66
"repository": "sindresorhus/env-paths",
7+
"funding": "https://github.com/sponsors/sindresorhus",
78
"author": {
89
"name": "Sindre Sorhus",
910
"email": "sindresorhus@gmail.com",
10-
"url": "sindresorhus.com"
11+
"url": "https://sindresorhus.com"
1112
},
13+
"type": "module",
14+
"exports": "./index.js",
1215
"engines": {
13-
"node": ">=6"
16+
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
1417
},
1518
"scripts": {
1619
"test": "xo && ava && tsd"
@@ -38,8 +41,8 @@
3841
"unix"
3942
],
4043
"devDependencies": {
41-
"ava": "^1.4.1",
42-
"tsd": "^0.7.1",
43-
"xo": "^0.24.0"
44+
"ava": "^3.15.0",
45+
"tsd": "^0.17.0",
46+
"xo": "^0.44.0"
4447
}
4548
}

readme.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,16 @@
44
55
Uses the correct OS-specific paths. Most developers get this wrong.
66

7-
87
## Install
98

109
```
1110
$ npm install env-paths
1211
```
1312

14-
1513
## Usage
1614

1715
```js
18-
const envPaths = require('env-paths');
16+
import envPaths from 'env-paths';
1917

2018
const paths = envPaths('MyApp');
2119

@@ -26,7 +24,6 @@ paths.config
2624
//=> '/home/sindresorhus/.config/MyApp-nodejs'
2725
```
2826

29-
3027
## API
3128

3229
### paths = envPaths(name, options?)
@@ -37,18 +34,19 @@ Note: It only generates the path strings. It doesn't create the directories for
3734

3835
Type: `string`
3936

40-
Name of your project. Used to generate the paths.
37+
The name of your project. Used to generate the paths.
4138

4239
#### options
4340

4441
Type: `object`
4542

4643
##### suffix
4744

48-
Type: `string`<br>
45+
Type: `string`\
4946
Default: `'nodejs'`
5047

51-
**Don't use this option unless you really have to!**<br>
48+
**Don't use this option unless you really have to!**
49+
5250
Suffix appended to the project name to avoid name conflicts with native
5351
apps. Pass an empty string to disable it.
5452

test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import process from 'node:process';
12
import test from 'ava';
2-
import envPaths from '.';
3+
import envPaths from './index.js';
34

45
test('default', t => {
56
const name = 'unicorn';
@@ -13,15 +14,14 @@ test('default', t => {
1314

1415
test('custom suffix', t => {
1516
const name = 'unicorn';
16-
const opts = {suffix: 'horn'};
17-
const paths = envPaths(name, opts);
18-
t.true(paths.data.endsWith(`${name}-${opts.suffix}`));
17+
const options = {suffix: 'horn'};
18+
const paths = envPaths(name, options);
19+
t.true(paths.data.endsWith(`${name}-${options.suffix}`));
1920
});
2021

2122
test('no suffix', t => {
2223
const name = 'unicorn';
23-
const opts = {suffix: false};
24-
const paths = envPaths(name, opts);
24+
const paths = envPaths(name, {suffix: false});
2525
t.true(paths.data.endsWith(name));
2626
});
2727

@@ -32,7 +32,7 @@ if (process.platform === 'linux') {
3232
data: 'XDG_DATA_HOME',
3333
config: 'XDG_CONFIG_HOME',
3434
cache: 'XDG_CACHE_HOME',
35-
log: 'XDG_STATE_HOME'
35+
log: 'XDG_STATE_HOME',
3636
};
3737

3838
for (const env of Object.values(envVars)) {

0 commit comments

Comments
 (0)