Skip to content

Commit cd1bccf

Browse files
committedAug 14, 2021
Rename the readPackageAsync export to readPackage
1 parent e6fdae4 commit cd1bccf

File tree

7 files changed

+30
-31
lines changed

7 files changed

+30
-31
lines changed
 

‎.github/workflows/main.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
node-version:
13-
- 14
14-
- 12
13+
- 16
1514
steps:
1615
- uses: actions/checkout@v2
17-
- uses: actions/setup-node@v1
16+
- uses: actions/setup-node@v2
1817
with:
1918
node-version: ${{ matrix.node-version }}
2019
- run: npm install

‎index.d.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ export type PackageJson = typeFest.PackageJson;
2929
3030
@example
3131
```
32-
import {readPackageAsync} from 'read-pkg';
32+
import {readPackage} from 'read-pkg';
3333
34-
console.log(await readPackageAsync());
34+
console.log(await readPackage());
3535
//=> {name: 'read-pkg', …}
3636
37-
console.log(await readPackageAsync({cwd: 'some-other-directory'});
37+
console.log(await readPackage({cwd: 'some-other-directory'});
3838
//=> {name: 'unicorn', …}
3939
```
4040
*/
41-
export function readPackageAsync(options?: NormalizeOptions): Promise<NormalizedPackageJson>;
42-
export function readPackageAsync(options: Options): Promise<PackageJson>;
41+
export function readPackage(options?: NormalizeOptions): Promise<NormalizedPackageJson>;
42+
export function readPackage(options: Options): Promise<PackageJson>;
4343

4444
/**
4545
@returns The parsed JSON.

‎index.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import fs, {promises as fsAsync} from 'fs';
2-
import path from 'path';
1+
import process from 'node:process';
2+
import fs, {promises as fsPromises} from 'node:fs';
3+
import path from 'node:path';
34
import parseJson from 'parse-json';
45
import normalizePackageData from 'normalize-package-data';
56

6-
export async function readPackageAsync({cwd = process.cwd(), normalize = true} = {}) {
7+
export async function readPackage({cwd = process.cwd(), normalize = true} = {}) {
78
const filePath = path.resolve(cwd, 'package.json');
8-
const json = parseJson(await fsAsync.readFile(filePath, 'utf8'));
9+
const json = parseJson(await fsPromises.readFile(filePath, 'utf8'));
910

1011
if (normalize) {
1112
normalizePackageData(json);

‎index.test-d.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
import {expectType, expectError, expectAssignable} from 'tsd';
2-
import {readPackageAsync, readPackageSync, Options, NormalizedPackageJson, PackageJson} from './index.js';
2+
import {readPackage, readPackageSync, NormalizedPackageJson, PackageJson} from './index.js';
33

4-
const options: Options = {};
54
expectError<NormalizedPackageJson>({});
65
expectAssignable<PackageJson>({});
76

8-
expectType<Promise<NormalizedPackageJson>>(readPackageAsync());
9-
expectType<Promise<NormalizedPackageJson>>(readPackageAsync({normalize: true}));
10-
expectType<Promise<PackageJson>>(readPackageAsync({normalize: false}));
7+
expectType<Promise<NormalizedPackageJson>>(readPackage());
8+
expectType<Promise<NormalizedPackageJson>>(readPackage({normalize: true}));
9+
expectType<Promise<PackageJson>>(readPackage({normalize: false}));
1110
expectError<Promise<NormalizedPackageJson>>(
12-
readPackageAsync({normalize: false})
11+
readPackage({normalize: false}),
1312
);
14-
expectType<Promise<NormalizedPackageJson>>(readPackageAsync({cwd: '.'}));
13+
expectType<Promise<NormalizedPackageJson>>(readPackage({cwd: '.'}));
1514

1615
expectType<NormalizedPackageJson>(readPackageSync());
1716
expectType<NormalizedPackageJson>(readPackageSync({normalize: true}));

‎package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"type": "module",
1414
"exports": "./index.js",
1515
"engines": {
16-
"node": ">=12"
16+
"node": ">=12.20"
1717
},
1818
"scripts": {
1919
"test": "xo && ava && tsd"
@@ -34,15 +34,15 @@
3434
"normalize"
3535
],
3636
"dependencies": {
37-
"@types/normalize-package-data": "^2.4.0",
37+
"@types/normalize-package-data": "^2.4.1",
3838
"normalize-package-data": "^3.0.2",
3939
"parse-json": "^5.2.0",
40-
"type-fest": "^1.0.1"
40+
"type-fest": "^2.0.0"
4141
},
4242
"devDependencies": {
4343
"ava": "^3.15.0",
44-
"tsd": "^0.14.0",
45-
"xo": "^0.38.2"
44+
"tsd": "^0.17.0",
45+
"xo": "^0.44.0"
4646
},
4747
"xo": {
4848
"ignores": [

‎readme.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ $ npm install read-pkg
1616
## Usage
1717

1818
```js
19-
import {readPackageAsync} from 'read-pkg';
19+
import {readPackage} from 'read-pkg';
2020

21-
console.log(await readPackageAsync());
21+
console.log(await readPackage());
2222
//=> {name: 'read-pkg', …}
2323

24-
console.log(await readPackageAsync({cwd: 'some-other-directory'}));
24+
console.log(await readPackage({cwd: 'some-other-directory'}));
2525
//=> {name: 'unicorn', …}
2626
```
2727

2828
## API
2929

30-
### readPackageAsync(options?)
30+
### readPackage(options?)
3131

3232
Returns a `Promise<object>` with the parsed JSON.
3333

‎test/test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import {fileURLToPath} from 'url';
22
import path from 'path';
33
import test from 'ava';
4-
import {readPackageAsync, readPackageSync} from '../index.js';
4+
import {readPackage, readPackageSync} from '../index.js';
55

66
const dirname = path.dirname(fileURLToPath(import.meta.url));
77
process.chdir(dirname);
88
const rootCwd = path.join(dirname, '..');
99

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

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

0 commit comments

Comments
 (0)
Please sign in to comment.