Skip to content

Commit 267b050

Browse files
committed
Require Node.js 8
Closes #9
1 parent 03b601f commit 267b050

File tree

4 files changed

+73
-70
lines changed

4 files changed

+73
-70
lines changed

index.js

+16-17
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,34 @@
11
'use strict';
2+
const {promisify} = require('util');
23
const fs = require('fs');
34
const path = require('path');
45
const parseJson = require('parse-json');
5-
const pify = require('pify');
66

7-
const readFileAsync = pify(fs.readFile);
7+
const readFileAsync = promisify(fs.readFile);
88

9-
module.exports = options => {
10-
options = Object.assign({
9+
module.exports = async options => {
10+
options = {
1111
cwd: process.cwd(),
12-
normalize: true
13-
}, options);
12+
normalize: true,
13+
...options
14+
};
1415

1516
const filePath = path.resolve(options.cwd, 'package.json');
17+
const json = parseJson(await readFileAsync(filePath, 'utf8'));
1618

17-
return readFileAsync(filePath, 'utf8').then(file => {
18-
const json = parseJson(file);
19-
20-
if (options.normalize) {
21-
require('normalize-package-data')(json);
22-
}
19+
if (options.normalize) {
20+
require('normalize-package-data')(json);
21+
}
2322

24-
return json;
25-
});
23+
return json;
2624
};
2725

2826
module.exports.sync = options => {
29-
options = Object.assign({
27+
options = {
3028
cwd: process.cwd(),
31-
normalize: true
32-
}, options);
29+
normalize: true,
30+
...options
31+
};
3332

3433
const filePath = path.resolve(options.cwd, 'package.json');
3534
const json = parseJson(fs.readFileSync(filePath, 'utf8'));

package.json

+44-40
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,46 @@
11
{
2-
"name": "read-pkg",
3-
"version": "4.0.1",
4-
"description": "Read a package.json file",
5-
"license": "MIT",
6-
"repository": "sindresorhus/read-pkg",
7-
"author": {
8-
"name": "Sindre Sorhus",
9-
"email": "[email protected]",
10-
"url": "sindresorhus.com"
11-
},
12-
"engines": {
13-
"node": ">=6"
14-
},
15-
"scripts": {
16-
"test": "xo && ava"
17-
},
18-
"files": [
19-
"index.js"
20-
],
21-
"keywords": [
22-
"json",
23-
"read",
24-
"parse",
25-
"file",
26-
"fs",
27-
"graceful",
28-
"load",
29-
"pkg",
30-
"package",
31-
"normalize"
32-
],
33-
"dependencies": {
34-
"normalize-package-data": "^2.3.2",
35-
"parse-json": "^4.0.0",
36-
"pify": "^3.0.0"
37-
},
38-
"devDependencies": {
39-
"ava": "*",
40-
"xo": "*"
41-
}
2+
"name": "read-pkg",
3+
"version": "4.0.1",
4+
"description": "Read a package.json file",
5+
"license": "MIT",
6+
"repository": "sindresorhus/read-pkg",
7+
"author": {
8+
"name": "Sindre Sorhus",
9+
"email": "[email protected]",
10+
"url": "sindresorhus.com"
11+
},
12+
"engines": {
13+
"node": ">=8"
14+
},
15+
"scripts": {
16+
"test": "xo && ava"
17+
},
18+
"files": [
19+
"index.js"
20+
],
21+
"keywords": [
22+
"json",
23+
"read",
24+
"parse",
25+
"file",
26+
"fs",
27+
"graceful",
28+
"load",
29+
"pkg",
30+
"package",
31+
"normalize"
32+
],
33+
"dependencies": {
34+
"normalize-package-data": "^2.3.2",
35+
"parse-json": "^4.0.0"
36+
},
37+
"devDependencies": {
38+
"ava": "^1.3.1",
39+
"xo": "^0.24.0"
40+
},
41+
"xo": {
42+
"ignores": [
43+
"test/test.js"
44+
]
45+
}
4246
}

readme.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ const readPkg = require('read-pkg');
2424

2525
(async () => {
2626
console.log(await readPkg());
27-
//=> {name: 'read-pkg', ...}
27+
//=> {name: 'read-pkg', }
2828

2929
console.log(await readPkg({cwd: 'some-other-directory'});
30-
//=> {name: 'unicorn', ...}
30+
//=> {name: 'unicorn', }
3131
})();
3232
```
3333

test/test.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
'use strict';
22
import path from 'path';
33
import test from 'ava';
4-
import m from '..';
4+
import readPackage from '..';
55

66
process.chdir(__dirname);
77

88
const rootCwd = path.join(__dirname, '..');
99

1010
test('async', async t => {
11-
const x = await m();
12-
t.is(x.name, 'unicorn');
13-
t.truthy(x._id);
11+
const package_ = await readPackage();
12+
t.is(package_.name, 'unicorn');
13+
t.truthy(package_._id);
1414
});
1515

1616
test('async - cwd option', async t => {
17-
const x = await m({cwd: rootCwd});
18-
t.is(x.name, 'read-pkg');
17+
const package_ = await readPackage({cwd: rootCwd});
18+
t.is(package_.name, 'read-pkg');
1919
});
2020

2121
test('sync', t => {
22-
const x = m.sync();
23-
t.is(x.name, 'unicorn');
24-
t.truthy(x._id);
22+
const package_ = readPackage.sync();
23+
t.is(package_.name, 'unicorn');
24+
t.truthy(package_._id);
2525
});
2626

2727
test('sync - cwd option', t => {
28-
const x = m.sync({cwd: rootCwd});
29-
t.is(x.name, 'read-pkg');
28+
const package_ = readPackage.sync({cwd: rootCwd});
29+
t.is(package_.name, 'read-pkg');
3030
});

0 commit comments

Comments
 (0)