Skip to content

Commit 120a81e

Browse files
committed
Require Node.js 18 and move to ESM
1 parent 57aa7aa commit 120a81e

File tree

10 files changed

+193
-204
lines changed

10 files changed

+193
-204
lines changed

.github/funding.yml

Lines changed: 0 additions & 4 deletions
This file was deleted.

.github/workflows/main.yml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,14 @@ jobs:
1212
node-version:
1313
- 20
1414
- 18
15-
- 16
16-
- 14
17-
- 12
18-
- 10
1915
os:
2016
- ubuntu-latest
2117
- macos-latest
2218
- windows-latest
2319
steps:
24-
- uses: actions/checkout@v3
25-
- uses: actions/setup-node@v3
20+
- uses: actions/checkout@v4
21+
- uses: actions/setup-node@v4
2622
with:
2723
node-version: ${{ matrix.node-version }}
2824
- run: npm install
2925
- run: npm test
30-
- uses: codecov/codecov-action@v3
31-
if: matrix.os == 'ubuntu-latest' && matrix.node-version == 14
32-
with:
33-
fail_ci_if_error: true

index.d.ts

Lines changed: 58 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,67 @@
1-
/// <reference types="node"/>
2-
import * as fs from 'fs';
1+
import type * as fs from 'node:fs';
32

4-
declare namespace makeDir {
5-
interface Options {
6-
/**
7-
Directory [permissions](https://x-team.com/blog/file-system-permissions-umask-node-js/).
8-
9-
@default 0o777
10-
*/
11-
readonly mode?: number;
12-
13-
/**
14-
Use a custom `fs` implementation. For example [`graceful-fs`](https://github.com/isaacs/node-graceful-fs).
15-
16-
Using a custom `fs` implementation will block the use of the native `recursive` option if `fs.mkdir` or `fs.mkdirSync` is not the native function.
17-
18-
@default require('fs')
19-
*/
20-
readonly fs?: typeof fs;
21-
}
22-
}
23-
24-
declare const makeDir: {
3+
export type Options = {
254
/**
26-
Make a directory and its parents if needed - Think `mkdir -p`.
27-
28-
@param path - Directory to create.
29-
@returns The path to the created directory.
30-
31-
@example
32-
```
33-
import makeDir = require('make-dir');
34-
35-
(async () => {
36-
const path = await makeDir('unicorn/rainbow/cake');
37-
38-
console.log(path);
39-
//=> '/Users/sindresorhus/fun/unicorn/rainbow/cake'
40-
41-
// Multiple directories:
42-
const paths = await Promise.all([
43-
makeDir('unicorn/rainbow'),
44-
makeDir('foo/bar')
45-
]);
46-
47-
console.log(paths);
48-
// [
49-
// '/Users/sindresorhus/fun/unicorn/rainbow',
50-
// '/Users/sindresorhus/fun/foo/bar'
51-
// ]
52-
})();
53-
```
5+
The directory [permissions](https://x-team.com/blog/file-system-permissions-umask-node-js/).
6+
7+
@default 0o777
548
*/
55-
(path: string, options?: makeDir.Options): Promise<string>;
9+
readonly mode?: number;
5610

5711
/**
58-
Synchronously make a directory and its parents if needed - Think `mkdir -p`.
12+
Use a custom `fs` implementation. For example [`graceful-fs`](https://github.com/isaacs/node-graceful-fs).
13+
14+
Using a custom `fs` implementation will block the use of the native `recursive` option if `fs.mkdir` or `fs.mkdirSync` is not the native function.
5915
60-
@param path - Directory to create.
61-
@returns The path to the created directory.
16+
Default: `import fs from 'node:fs'`
6217
*/
63-
sync(path: string, options?: makeDir.Options): string;
18+
readonly fs?: typeof fs;
6419
};
6520

66-
export = makeDir;
21+
/**
22+
Make a directory and its parents if needed - Think `mkdir -p`.
23+
24+
@param path - The directory to create.
25+
@returns The path to the created directory.
26+
27+
@example
28+
```
29+
import {makeDirectory} from 'make-dir';
30+
31+
const path = await makeDirectory('unicorn/rainbow/cake');
32+
33+
console.log(path);
34+
//=> '/Users/sindresorhus/fun/unicorn/rainbow/cake'
35+
36+
// Multiple directories:
37+
const paths = await Promise.all([
38+
makeDirectory('unicorn/rainbow'),
39+
makeDirectory('foo/bar')
40+
]);
41+
42+
console.log(paths);
43+
// [
44+
// '/Users/sindresorhus/fun/unicorn/rainbow',
45+
// '/Users/sindresorhus/fun/foo/bar'
46+
// ]
47+
```
48+
*/
49+
export function makeDirectory(path: string, options?: Options): Promise<string>;
50+
51+
/**
52+
Synchronously make a directory and its parents if needed - Think `mkdir -p`.
53+
54+
@param path - The directory to create.
55+
@returns The path to the created directory.
56+
57+
@example
58+
```
59+
import {makeDirectorySync} from 'make-dir';
60+
61+
const path = makeDirectorySync('unicorn/rainbow/cake');
62+
63+
console.log(path);
64+
//=> '/Users/sindresorhus/fun/unicorn/rainbow/cake'
65+
```
66+
*/
67+
export function makeDirectorySync(path: string, options?: Options): string;

index.js

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
'use strict';
2-
const fs = require('fs');
3-
const path = require('path');
4-
const {promisify} = require('util');
5-
const semverGte = require('semver/functions/gte');
6-
7-
const useNativeRecursiveOption = semverGte(process.version, '10.12.0');
1+
import process from 'node:process';
2+
import fs from 'node:fs';
3+
import fsPromises from 'node:fs/promises';
4+
import path from 'node:path';
85

96
// https://github.com/nodejs/node/issues/8987
107
// https://github.com/libuv/libuv/pull/1088
@@ -23,12 +20,12 @@ const checkPath = pth => {
2320
const processOptions = options => {
2421
const defaults = {
2522
mode: 0o777,
26-
fs
23+
fs,
2724
};
2825

2926
return {
3027
...defaults,
31-
...options
28+
...options,
3229
};
3330
};
3431

@@ -43,27 +40,24 @@ const permissionError = pth => {
4340
return error;
4441
};
4542

46-
const makeDir = async (input, options) => {
43+
export async function makeDirectory(input, options) {
4744
checkPath(input);
4845
options = processOptions(options);
4946

50-
const mkdir = promisify(options.fs.mkdir);
51-
const stat = promisify(options.fs.stat);
52-
53-
if (useNativeRecursiveOption && options.fs.mkdir === fs.mkdir) {
47+
if (options.fs.mkdir === fs.mkdir) {
5448
const pth = path.resolve(input);
5549

56-
await mkdir(pth, {
50+
await fsPromises.mkdir(pth, {
5751
mode: options.mode,
58-
recursive: true
52+
recursive: true,
5953
});
6054

6155
return pth;
6256
}
6357

6458
const make = async pth => {
6559
try {
66-
await mkdir(pth, options.mode);
60+
await fsPromises.mkdir(pth, options.mode);
6761

6862
return pth;
6963
} catch (error) {
@@ -86,7 +80,7 @@ const makeDir = async (input, options) => {
8680
}
8781

8882
try {
89-
const stats = await stat(pth);
83+
const stats = await fsPromises.stat(pth);
9084
if (!stats.isDirectory()) {
9185
throw new Error('The path is not a directory');
9286
}
@@ -99,20 +93,18 @@ const makeDir = async (input, options) => {
9993
};
10094

10195
return make(path.resolve(input));
102-
};
96+
}
10397

104-
module.exports = makeDir;
105-
106-
module.exports.sync = (input, options) => {
98+
export function makeDirectorySync(input, options) {
10799
checkPath(input);
108100
options = processOptions(options);
109101

110-
if (useNativeRecursiveOption && options.fs.mkdirSync === fs.mkdirSync) {
102+
if (options.fs.mkdirSync === fs.mkdirSync) {
111103
const pth = path.resolve(input);
112104

113105
fs.mkdirSync(pth, {
114106
mode: options.mode,
115-
recursive: true
107+
recursive: true,
116108
});
117109

118110
return pth;
@@ -152,4 +144,4 @@ module.exports.sync = (input, options) => {
152144
};
153145

154146
return make(path.resolve(input));
155-
};
147+
}

index.test-d.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1+
import * as fs from 'node:fs';
12
import {expectType} from 'tsd';
2-
import makeDir = require('.');
3-
import {sync as makeDirSync} from '.';
4-
import * as fs from 'fs';
53
import * as gfs from 'graceful-fs';
4+
import {makeDirectory, makeDirectorySync} from './index.js';
65

76
// MakeDir
8-
expectType<Promise<string>>(makeDir('path/to/somewhere'));
7+
expectType<Promise<string>>(makeDirectory('path/to/somewhere'));
98

109
expectType<Promise<string>>(
11-
makeDir('path/to/somewhere', {mode: 0o777})
10+
makeDirectory('path/to/somewhere', {mode: 0o777}),
1211
);
13-
expectType<Promise<string>>(makeDir('path/to/somewhere', {fs}));
14-
expectType<Promise<string>>(makeDir('path/to/somewhere', {fs: gfs}));
12+
expectType<Promise<string>>(makeDirectory('path/to/somewhere', {fs}));
13+
expectType<Promise<string>>(makeDirectory('path/to/somewhere', {fs: gfs}));
1514

1615
// MakeDir (sync)
17-
expectType<string>(makeDirSync('path/to/somewhere'));
16+
expectType<string>(makeDirectorySync('path/to/somewhere'));
1817

1918
expectType<string>(
20-
makeDirSync('path/to/somewhere', {mode: 0o777})
19+
makeDirectorySync('path/to/somewhere', {mode: 0o777}),
2120
);
22-
expectType<string>(makeDirSync('path/to/somewhere', {fs}));
23-
expectType<string>(makeDirSync('path/to/somewhere', {fs: gfs}));
21+
expectType<string>(makeDirectorySync('path/to/somewhere', {fs}));
22+
expectType<string>(makeDirectorySync('path/to/somewhere', {fs: gfs}));

package.json

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,17 @@
1010
"email": "[email protected]",
1111
"url": "https://sindresorhus.com"
1212
},
13+
"type": "module",
14+
"exports": {
15+
"types": "./index.d.ts",
16+
"default": "./index.js"
17+
},
18+
"sideEffects": false,
1319
"engines": {
14-
"node": ">=10"
20+
"node": ">=18"
1521
},
1622
"scripts": {
17-
"test": "xo && nyc ava && tsd"
23+
"test": "xo && ava && tsd"
1824
},
1925
"files": [
2026
"index.js",
@@ -39,25 +45,17 @@
3945
"filesystem",
4046
"file-system"
4147
],
42-
"dependencies": {
43-
"semver": "^7.5.3"
44-
},
4548
"devDependencies": {
46-
"@types/graceful-fs": "^4.1.3",
47-
"@types/node": "^14.14.6",
48-
"ava": "^2.4.0",
49-
"codecov": "^3.2.0",
50-
"graceful-fs": "^4.1.15",
51-
"nyc": "^15.0.0",
52-
"path-type": "^4.0.0",
53-
"tempy": "^1.0.0",
54-
"tsd": "^0.13.1",
55-
"xo": "^0.34.2"
49+
"@types/graceful-fs": "^4.1.9",
50+
"@types/node": "^20.12.8",
51+
"ava": "^6.1.2",
52+
"graceful-fs": "^4.2.11",
53+
"path-type": "^5.0.0",
54+
"tempy": "^3.1.0",
55+
"tsd": "^0.31.0",
56+
"xo": "^0.58.0"
5657
},
57-
"nyc": {
58-
"reporter": [
59-
"text",
60-
"lcov"
61-
]
58+
"ava": {
59+
"workerThreads": false
6260
}
6361
}

0 commit comments

Comments
 (0)