Skip to content

Commit 869e0d1

Browse files
committed
feature(readify) drop support of node < 10
1 parent a9fd0e1 commit 869e0d1

File tree

6 files changed

+26
-37
lines changed

6 files changed

+26
-37
lines changed

.eslintrc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
2+
"rules": {
3+
"node/no-unsupported-features/node-builtins": "off"
4+
},
25
"extends": [
36
"plugin:putout/recommended",
47
"plugin:node/recommended"

lib/readdir.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
'use strict';
22

33
const {join} = require('path');
4-
const {promisify} = require('util');
5-
const fs = require('fs');
4+
const {readdir} = require('fs').promises;
65

76
const tryToCatch = require('try-to-catch');
87
const superstat = require('superstat');
98

109
const noop = function() {};
11-
const readdir = promisify(fs.readdir);
1210

1311
const {assign} = Object;
1412

lib/readify.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ async function readify(path, options = {}) {
3333
const sorted = sortify({sort, order}, names);
3434
const formated = ifRaw(type, formatify, sorted);
3535

36-
return fillJSON(path, type, formated);
36+
return await fillJSON(path, type, formated);
3737
}
3838

3939
function check(path, type) {

madrun.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const {run} = require('madrun');
44

55
module.exports = {
66
'lint': () => 'putout lib test madrun.js',
7-
'fix:lint': () => run(['putout', 'lint:*'], '--fix'),
7+
'fix:lint': () => run('lint', '--fix'),
88
'report': () => 'nyc report --reporter=text-lcov | coveralls',
99
'coverage': () => 'nyc npm test',
1010
'test': () => 'tape test/*.js',

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@
1515
]
1616
},
1717
"scripts": {
18-
"putout": "madrun putout",
1918
"lint": "madrun lint",
2019
"fix:lint": "madrun fix:lint",
21-
"lint:eslint:lib": "madrun lint:eslint:lib",
22-
"lint:eslint:test": "madrun lint:eslint:test",
2320
"report": "madrun report",
2421
"coverage": "madrun coverage",
2522
"test": "madrun test",
@@ -52,7 +49,7 @@
5249
"license": "MIT",
5350
"main": "lib/readify.js",
5451
"engines": {
55-
"node": ">=8.3.0"
52+
"node": ">=10"
5653
},
5754
"devDependencies": {
5855
"@cloudcmd/stub": "^2.0.0",

test/readdir.js

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

33
const fs = require('fs');
4-
const {callbackify} = require('util');
54

65
const stub = require('@cloudcmd/stub');
76
const test = require('supertape');
@@ -12,35 +11,35 @@ const tryToCatch = require('try-to-catch');
1211
const noop = () => {};
1312

1413
test('readdir: empty dir', async (t) => {
15-
const {readdir} = fs;
16-
fs.readdir = callbackify(async () => []);
14+
const {readdir} = fs.promises;
15+
fs.promises.readdir = async () => [];
1716

1817
const _readdir = reRequire('../lib/readdir');
1918

2019
const [, result] = await tryToCatch(_readdir, '.');
2120

22-
fs.readdir = readdir;
21+
fs.promises.readdir = readdir;
2322

2423
t.deepEqual(result, [], 'should return empty array');
2524
t.end();
2625
});
2726

2827
test('readdir: empty stat', async (t) => {
29-
const {readdir} = fs;
28+
const {readdir} = fs.promises;
3029

3130
mockRequire('superstat', async () => {
3231
throw Error('some');
3332
});
3433

35-
fs.readdir = callbackify(async () => [
34+
fs.promises.readdir = async () => [
3635
'hello',
37-
]);
36+
];
3837

3938
const _readdir = reRequire('../lib/readdir');
4039

4140
const [, result] = await tryToCatch(_readdir, '/');
4241

43-
fs.readdir = readdir;
42+
fs.promises.readdir = readdir;
4443

4544
const expected = [{
4645
name: 'hello',
@@ -58,17 +57,15 @@ test('readdir: empty stat', async (t) => {
5857
});
5958

6059
test('readdir: result', async (t) => {
61-
const {readdir} = fs;
60+
const {readdir} = fs.promises;
6261

6362
const name = 'hello.txt';
6463
const mode = 16893;
6564
const size = 1024;
6665
const mtime = new Date();
6766
const uid = 1000;
6867

69-
fs.readdir = (dir, fn) => {
70-
fn(null, [name]);
71-
};
68+
fs.promises.readdir = async () => [name];
7269

7370
mockRequire('superstat', async () => ({
7471
isDirectory: noop,
@@ -92,25 +89,23 @@ test('readdir: result', async (t) => {
9289
const _readdir = reRequire('../lib/readdir');
9390
const [, result] = await tryToCatch(_readdir, '.');
9491

95-
fs.readdir = readdir;
92+
fs.promises.readdir = readdir;
9693
stopAll();
9794

9895
t.deepEqual(result, expected, 'should get raw values');
9996
t.end();
10097
});
10198

10299
test('readdir: result: no error', async (t) => {
103-
const {readdir} = fs;
100+
const {readdir} = fs.promises;
104101

105102
const name = 'hello.txt';
106103
const mode = 16893;
107104
const size = 1024;
108105
const mtime = new Date();
109106
const uid = 1000;
110107

111-
fs.readdir = (dir, fn) => {
112-
fn(null, [name]);
113-
};
108+
fs.promises.readdir = () => [name];
114109

115110
mockRequire('superstat', async () => ({
116111
isDirectory: noop,
@@ -126,24 +121,22 @@ test('readdir: result: no error', async (t) => {
126121
const [e] = await tryToCatch(_readdir, '.');
127122

128123
stopAll();
129-
fs.readdir = readdir;
124+
fs.promises.readdir = readdir;
130125

131126
t.notOk(e, e && e.message || 'should not receive error');
132127
t.end();
133128
});
134129

135130
test('readdir: result: directory link', async (t) => {
136-
const {readdir} = fs;
131+
const {readdir} = fs.promises;
137132

138133
const name = 'hello';
139134
const mode = 16893;
140135
const size = 1024;
141136
const mtime = new Date();
142137
const uid = 1000;
143138

144-
fs.readdir = (dir, fn) => {
145-
fn(null, [name]);
146-
};
139+
fs.promises.readdir = () => [name];
147140

148141
const info = {
149142
isDirectory: stub().returns(true),
@@ -171,25 +164,23 @@ test('readdir: result: directory link', async (t) => {
171164
const _readdir = reRequire('../lib/readdir');
172165
const [, result] = await tryToCatch(_readdir, '.');
173166

174-
fs.readdir = readdir;
167+
fs.promises.readdir = readdir;
175168
stopAll();
176169

177170
t.deepEqual(result, expected, 'should get raw values');
178171
t.end();
179172
});
180173

181174
test('readdir: result: directory link: no error', async (t) => {
182-
const {readdir} = fs;
175+
const {readdir} = fs.promises;
183176

184177
const name = 'hello';
185178
const mode = 16893;
186179
const size = 1024;
187180
const mtime = new Date();
188181
const uid = 1000;
189182

190-
fs.readdir = (dir, fn) => {
191-
fn(null, [name]);
192-
};
183+
fs.promises.readdir = () => [name];
193184

194185
mockRequire('superstat', async () => ({
195186
isDirectory: stub.returns(true),
@@ -205,7 +196,7 @@ test('readdir: result: directory link: no error', async (t) => {
205196
const [e] = await tryToCatch(_readdir, '.');
206197

207198
stopAll();
208-
fs.readdir = readdir;
199+
fs.promises.readdir = readdir;
209200

210201
t.notOk(e, e && e.message || 'should not receive error');
211202
t.end();

0 commit comments

Comments
 (0)